Fixed Assembly Version with Auto Incremented File Version?

不羁岁月 提交于 2019-12-03 10:35:12

问题


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?


回答1:


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.


来源:https://stackoverflow.com/questions/12307435/fixed-assembly-version-with-auto-incremented-file-version

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!