Chase Florell
Chase Florell

Reputation: 47437

How to get buildnumber / revision from Assembly? (4th digit)

Our build process updates the forth digit (buildnumber or revision) of the version number on every build.

enter image description here

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?

enter image description here

Upvotes: 0

Views: 163

Answers (1)

George Lica
George Lica

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

Related Questions