My supervison, coming from a non-.net background wants me to use his special version numbering scheme as major.minor.revision.build[-Dev|RC1|RC2]. He wants to be able to right-click on the dll and see the version number like this or retrieve the version number from the Dll or Exe to display. I don't see how and my research says MS just doesn't support this kind of thing. I need a work around. Any ideas?
Oh yeah, coding in VS2008 VB.Net on Windows XP Pro SP3.
Thanks!
Nope. As you can see from:
http://msdn.microsoft.com/en-us/library/system.version.aspx
The Version class has Int32 values for all the version components, and the ability to compare version numbers with each other.
Excerpt:
Version numbers consist of two to four components: major, minor, build, and revision. The major and minor components are required; the build and revision components are optional, but the build component is required if the revision component is defined. All defined components must be integers greater than or equal to 0. The format of the version number is as follows (optional components are shown in square brackets ([ and ]):
I know this is an old post, but I ran across this today. https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assemblyinformationalversionattribute?view=net-5.0
Apparently this attribute has been present since .Net 1.1. You can also use non-standard version in FileVersion, but you will get a compiler warning. AssemblyVersion won't compile if it isn't in the correct format. InformationalVersion can be apparently anything.
If you set a non-standard FileVersion, Windows Properties tries to parse it as a normal version, so in my example screenshots below, the '-RC1' gets dropped. If you put in something nonsensical (like 'blarg'), then it just becomes '0.0.0.0' for the file version.
In your code, if you are a WinForms project, you can access the new information version from Application.ProductVersion. For non-WinForms, to avoid loading the WinForms DLL into memory, you can basically copy the code from the reference source code for Application.ProductVersion. Either way, it is a string, so if you want to do any kind of comparison logic in your code, if you can't immediately parse it as Version object, you will need to write your own parser / comparer.
Assembly entryAssembly = Assembly.GetEntryAssembly();
if (entryAssembly != null) {
object[] attrs = entryAssembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
if (attrs != null && attrs.Length > 0) {
productVersion = ((AssemblyInformationalVersionAttribute)attrs[0]).InformationalVersion;
}
}


If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With