Programatically getting my AssemblyVersion

H

herc

How does one get the AssemblyVersion of the currently excuting
assembly? At first glance, it would appear that this would give you
the AsseblyName which will give you the version:

string appName =
AppDomain.CurrentDomain.SetupInformation.ApplicationName;
AssemblyName assemblyName = AssemblyName.GetAssemblyName(appName);

But the appname is <name>.vshost.exe. Is there any way to find out the
name of the assembly minus the vshost?
 
H

herc

The answer:

string appName = Assembly.GetAssembly(this.GetType()).Location;
AssemblyName assemblyName = AssemblyName.GetAssemblyName(appName);
return assemblyName.Version.ToString();
 
M

Mattias Sjögren

string appName = Assembly.GetAssembly(this.GetType()).Location;
AssemblyName assemblyName = AssemblyName.GetAssemblyName(appName);
return assemblyName.Version.ToString();

Or just

return this.GetType().Assembly.GetName().Version.ToString();


Mattias
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

herc said:
The answer:

string appName = Assembly.GetAssembly(this.GetType()).Location;
AssemblyName assemblyName = AssemblyName.GetAssemblyName(appName);
return assemblyName.Version.ToString();

A shorter way:

Assembly.GetExecutingAssembly().GetName.Version.ToString()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top