In VS 6, we had an autoincrement of the build number, if we build a new *.exe file. In VS.NET, I miss this feature. Here I submit a quick and dirty program (60 lines) which updates the version line in AssemblyInfo.cs each time a Release version is build.
Beau Scinner has written a lot about the basics, but it works only in VS 6. In VS.NET is AssemblyInfo.cs file, which contains the information of the
Application.ProductVersion in the form of one line:
IncBuildNo reads this file, increments the last number by 1 and writes it back.
IncBuildNo's 1st arg is the path and filename to AssemblyInfo.cs.
Optional it reads a 2nd arg
Release. If the 2nd arg is given, but if
arg!="Release", IncBuildNo returns without any action, I add this option, that IncBuildNo is able to select the VS.NET environment
If you omit this 2nd arg or the 2nd arg is
Release IncBuildNo increments the last number of the version string (otherwise it skips incrementing).
In the new version, I add some error-output to the Application Event Log.
If you download the project above, you have a complete installed example.
In your own projects, take the following steps:
- Copy IncBuildNo into the same directory as AssemblyInfo.cs (normally the
- In VS.NET, select Project -> Properties -> Build Events
- Insert in Post-build Event CommandLine:
"$(ProjectDir)IncBuildNo" "$(ProjectDir)AssemblyInfo.cs" $(ConfigurationName)
- Select in Run the Post-Build Event?
When build updates the project output
Now each time you build a new release, the last number of the version is incremented.
1st Note: After a successful build of a release, AssemblyInfo.cs shows the version of the release +1.
2nd Note: If you use a installation-project when you build your application, you can insert a line in the postbuild event property in the project properties of this installation project. I use e.g.
"$(ProjectDir)IncBuildNo" "$(ProjectDir)..\AssemblyInfo.cs" $(ConfigurationName)
Attention: In this case, the
$(ProjectDir) points to the install project, not to the application project. This is the reason for the
..\ phrase in the above line. But then the increment happened only if the building process is running, i.e., you can build a Release-Version without incrementing the build number.
I hope this will help you.