2

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!

Mike Christensen
  • 88,082
  • 50
  • 208
  • 326
irtheman
  • 43
  • 1
  • 7
  • OK. It is as I feared. I am stuck and must stand up to the supervisor. Thanks to everyone for the info. Also, I like Mike Christensen's idea for having a the supervisor's pet version number in the about box. I may continue to look for a way to simplify the addition of the special version number as I don't relish continually editing that file for each new version number but it is a great start. Maybe I can use that File Version Number as a flag for which text to add to the version number. Who knows. Thanks again! – irtheman Jan 17 '12 at 01:46

4 Answers4

3

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;
    }
}

Assembly Info Version Attribute

File Properties

B.O.B.
  • 704
  • 4
  • 10
  • thanks that help me, I use https://stackoverflow.com/questions/826777/how-to-have-an-auto-incrementing-version-number-visual-studio t4 template + as you advice but merge into final as [assembly: AssemblyInformationalVersion("<#= this.major #>.<#= this.minor #>.<#= this.revision #> (<#= this.channel #>: <#= this.build #>)")] – Gorodeckij Dimitrij Mar 03 '23 at 20:49
2

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 ]):

Mike Christensen
  • 88,082
  • 50
  • 208
  • 326
  • 1
    The workaround is to tell your boss No :) The version info is stored in the metadata of the assembly, and that's where the "right click properties thingy" gets it too. Version numbers are used for access control, GAC'ing, and other assembly binding. You could have a `Help->About` dialog that shows any version you want though! – Mike Christensen Jan 13 '12 at 19:20
1

If you want to install these applications using an installer that uses Microsoft installer technology (MSI), then the maximum granularity that is available is three digits (i.e. 1.1.1) and you are constrained to a fixed, positive numeric range for each number:

The first two fields (Major and Minor) can be no greater than 255 and the last field (Revision) can be no greater than 65535.

competent_tech
  • 44,465
  • 11
  • 90
  • 113
0

There is a Visual Studio Add-In that I always use. It works really very well. It is called Build Version Increment on CodePlex. What is nice is that you can configure it to generate the version number for you (and increment it) each time you do a Build and/or rebuild in Visual Studio.

It supports Visual Studio 2005 and 2008. There is now also a version released for Visual Studio 2010. Build Version Increment modifies your Assembly.cs file. I always set it to modify and increment my AssemblyVersion. Then in code, to get the version and display it on my form, I use the following code:

string strAssemblyVersion = "Version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

I hope that this helps you.

Dirk Strauss
  • 630
  • 1
  • 8
  • 19
  • That sounds like a useful tool. I am going to keep it in mind for future projects. My current job seems to like to control and manipulate the version numbers so much that automation may get in the way. :-) Thanks! – irtheman Jan 17 '12 at 01:42