How can I programmatically get the current product version in C#?
My code:
VersionNumber = System.Reflection.Assembly.GetExecutingAssembly().GetName
All these answers ask for the assembly with .GetExecutingAssembly()
.
If you have this code in a dll, it will return the dll version number.
Swap that call for GetCallingAssembly()
to get the place in your code that wanted to know.
///
/// Returns version like 2.1.15
///
public static String ProductVersion
{
get
{
return new Version(FileVersionInfo.GetVersionInfo(Assembly.GetCallingAssembly().Location).ProductVersion).ToString();
}
}