Reputation: 47437
Our build process updates the forth digit (buildnumber or revision) of the version number on every build.
I'm using the following code to try and get the version so that it can be displayed on the splash screen and about page.
var version = Assembly.GetEntryAssembly().GetName().Version;
var programName = "Version: " + version;
How come the 4th digit in the version number is always zero, and what can I change to get it to property reflect the build number?
Upvotes: 0
Views: 163
Reputation: 1816
Any assembly has two metadatas: the assembly version and the file version. The assembly version I don't know exactly how to take it. It seems that there is an AssemblyVersionAttribute but when I try to search for it, a null reference is returned.
But the File version you can take using this code:
public static Version GetAssemblyVersion (Assembly asm)
{
var attribute = Attribute.GetCustomAttribute(asm, typeof(AssemblyFileVersionAttribute), true) as AssemblyFileVersionAttribute;
return new Version(attribute.Version);
}
Generally, I use to synchronize so that file version = assembly version every time so I can grab assembly version using this code. Third party libraries, from my experience I can tell that are following this pattern also.
Upvotes: 1