Can I automatically increment the file build versi

2018-12-31 23:28发布

I was just wondering how I could automatically increment the build (and version?) of my files using Visual Studio (2005).

If I look up the properties of say C:\Windows\notepad.exe, the Version tab gives "File version: 5.1.2600.2180". I would like to get these cool numbers in the version of my dll's too, not version 1.0.0.0, which let's face it is a bit dull.

I tried a few things, but it doesn't seem to be out-of-box functionality, or maybe I'm just looking in the wrong place (as usual).

I work with mainly web projects....

I looked at both:

  1. http://www.codeproject.com/KB/dotnet/Auto_Increment_Version.aspx
  2. http://www.codeproject.com/KB/dotnet/build_versioning.aspx

and I couldn't believe it so much effort to do something is standard practice.

EDIT: It does not work in VS2005 as far I can tell (http://www.codeproject.com/KB/dotnet/AutoIncrementVersion.aspx)

23条回答
泪湿衣
2楼-- · 2018-12-31 23:44

Go to Project | Properties and then Assembly Information and then Assembly Version and put an * in the last or the second-to-last box (you can't auto-increment the Major or Minor components).

查看更多
有味是清欢
3楼-- · 2018-12-31 23:46

Install the Build Version Increment add-in. It gives you way more control than the * option.

查看更多
深知你不懂我心
4楼-- · 2018-12-31 23:48

Each time I do a build it auto-increments the least-significant digit.

I don't have any idea how to update the others, but you should at least be seeing that already...

查看更多
十年一品温如言
5楼-- · 2018-12-31 23:50

I'm using this approach https://stackoverflow.com/a/827209/3975786 by placing the T4 template in a "Solution Items" and using it with "Add as Link" within each project.

查看更多
伤终究还是伤i
6楼-- · 2018-12-31 23:52

To get the version numbers try

 System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
 System.Reflection.AssemblyName assemblyName = assembly.GetName();
 Version version = assemblyName.Version;

To set the version number, create/edit AssemblyInfo.cs

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

Also as a side note, the third number is the number of days since 2/1/2000 and the fourth number is half of the amount of total seconds in the day. So if you compile at midnight it should be zero.

查看更多
回忆,回不去的记忆
7楼-- · 2018-12-31 23:52

There is a visual studio extension Automatic Versions which supports Visual Studio 2012, 2013, 2015 & 2017.

Screen Shots enter image description here

enter image description here

查看更多
登录 后发表回答