Fixed Assembly Version with Auto Incremented File 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?


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:

  • Read the AssemblyInfo.cs file line by line.
  • 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.
  • Once you have the four integers, implement your own incrementing logic as you see fit.
  • 链接地址: http://www.djcxy.com/p/50674.html

    上一篇: 运行测试时获取HTTP错误403

    下一篇: 修正了自动递增文件版本的组装版本?