Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed Assembly Version with Auto Incremented File Version?

Tags:

c#

.net

version

I'm trying to find a more meaningful way to handle versioning for my app and I came acrossed this KB article

http://support.microsoft.com/kb/556041

Basically it's recommending that the Assembly version be fixed, and the File Version be imcremented for each build. Now this makes perfect sense to me but for the life of me I can't seem to implement it.

The below snippet auto increments both Assembly version and FileVersion.

[assembly: AssemblyVersion("1.0.*")]

While this next one seems to set a fixed Assembly version of 1.0.0.0 and a fixed File Version of 1.0.*.

[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("1.0.*")]

Incidentally, the Product Version in Details tab of the file properties reads 1.0.* now as well. Now I can fix the Product Version in the file properties with this...

[assembly: AssemblyInformationalVersion("1.0")]

But that doesn't help with my original task. Out of curiosity I tried the below and the File version changed to 2.0.*, so it is at least using it. It's just not auto incrementing.

[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("2.0.*")]

So from what I can gather the only version number that auto increments is the Assembly Version, but on the off chance you haven't specified a File Version it gets set to the same as the Assembly Version.

Does anyone know of a way to auto increment the File Version while leaving the Assembly Version fixed?

like image 328
Nick Albrecht Avatar asked Sep 06 '12 19:09

Nick Albrecht


People also ask

Can I automatically increment the file build version when using Visual Studio?

By default, Visual Studio automatically increments the Revision number of the Publish Version each time you publish the application. You can disable this behavior on the Publish page of the Project Designer.

What is the difference between assembly version and assembly file version?

AssemblyVersion: Specifies the version of the assembly being attributed. AssemblyFileVersion: Instructs a compiler to use a specific version number for the Win32 file version resource.

How do I find the assembly version of a DLL?

If you reference the dll in Visual Studio right click it (in ProjectName/References folder) and select "Properties" you have "Version" and "Runtime Version" there. In File Explorer when you right click the dll file and select properties there is a "File Version" and "Product Version" there.


1 Answers

Yes it's a bit silly, Microsoft seems to have got it the wrong way round. AssemblyVersion is used in the .NET assembly versioning system, so you should never auto-increment it, but AssemblyFileVersion is written to the file version entry in the file's version resource, so you might reasonably expect it to always auto-increment by default.

I'm sure that there are some 3rd party build systems out there that can do this for you, but I just wrote a little command line C# app to do it, and it gets run on every project as part of our build process. It's very straightforward:

  1. Read the AssemblyInfo.cs file line by line.
  2. Do a RegEx search for the AssemblyFileVersion line, capturing all four version parts into separate capture groups. You could parse it yourself, but a regex will do all the detecting and parsing in one go, so it seems silly not to take advantage.
  3. Once you have the four integers, implement your own incrementing logic as you see fit.
like image 86
Christian Hayter Avatar answered Nov 15 '22 17:11

Christian Hayter