Windows Service Assembly Version ?

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

Hi,

I know how to retrieve the Assembly Version for a WinForm program :
Application.ProductVersion.

But how to do it for a windows service in C# ???

Thx for your help

G.
 
I know how to retrieve the Assembly Version for a WinForm program :
Application.ProductVersion.

But how to do it for a windows service in C# ???

The assembly version is part of the assembly's name which can be retrieved
from the FullName property. Like this:
Assembly.GetExecutingAssembly().FullName

The full name has this form:
assembly name, Version=x.x.xxxx.xxxxx, Culture=culture, PublicKeyToken=token

where assembly name is the name of the assembly
x'es are numbers (the info you are looking for)
culture is the culture the assembly is complied for, usually neutral if the
assembly is not a satelite assembly
the public key token is used for strong name assemblies.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Thx for your answer.

I found another tip how to retrieve it :

System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion;
What do you think about this one ?



G.
 
System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion;
What do you think about this one ?
The above code does something different. It looks up version information for
the file not the assembly. This information might be the same, but using
this approach will require your application to have access to the filesystem
including rights to read the assembly.
Unless you need some of the additional information that the FileVersionInfo
class can give you such as CompanyName, ProductName and so on I recommend
that you retrieve the assembly version from the assembly it self.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Back
Top