Visual Studio: Auto-increment Build Number – Part 3/3

Follow this link for Part 1
Follow this link for part 2

Code Download

Download the zip file with example project and scripts here.

Unzip the package in a temporary folder and read and follow Readme.txt.

First Run

Read the Readme.txt file unzipped from the package downloaded above, and follow all the instruction carefully. Open Visual Studio project properties’ Build Event tab and update the path to PostBuild.Bat, as shown highlighted in the image below. Be cautious to have drive letter included and the full path is enclosed in quotes. Only update path inside the quotes.

Once you F6-build the test project, and if your project builds smoothly you will see Output (show output in Visual Studio from View menu) of the build has messages from auto-increment script. Messages will look something like this:

------ Build started: Project: AutoIncrementBuild, Configuration: Debug x86 ------
AutoIncrementBuild -> J:\Demo\Example\AutoIncrementBuild\bin\Debug\AutoIncrementBuild.exe
------------------------------ Post-build event started -------------------
Updating Build information...
Managing build...
Updating build log...
Log File Location: J:\Demo\Example\AutoIncrementBuild\BuildLog.txt
Dll File: J:\Demo\Example\AutoIncrementBuild\bin\Debug\AutoIncrementBuild.exe
Current Output Dll File Version: 1.7.3669.0
Build log entry for this build - 1.7.3669.0 - 16-10-2013 01:15:11 Debug XXX
Write version 1.7.3670.0 in VersionInfo file.
Written version 1.7.3670.0 in VersionInfo file
Confirmed version 1.7.3670.0 is written in VersionInfo file!
Build log updated successfully.
Build log updated
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

Messages above are self explanatory and does the commentary of all major tasks performed by the script. If there is any issue with the script, the error will be listed in output window.

On successful build of the project, BuildLog.txt file in your project directory should have a new entry with an incremented build number.


Let’s have a look at the Post-build event command line:
“J:\Demo\DevTools\AutoBuild\”PostBuild.bat MyParam ManageBLD “$(ProjectDir)” “$(TargetPath)” $(ConfigurationName)
Following are the details about each parameter and what you can do about them:

  • MyParam – In example, this is placeholder parameter. It does not affect auto-increment process, but you can pass some value for this parameter and in PostBuild.bat file, you can have some procedure called on the basis of value in this field. You can leave it as it is
  • ManageBLD – There are two recognizable values for this parameter: ManageBLD and NO_ManageBLD. If this parameter has any value other than ManageBld, Auto-increment will not kick in. You can pass NO_ManageBLD, if you want to skip auto-increment process.
  • $(ProjectDir) – Do not make any changes to this param
  • $(TargetPath) – Do not make any changes to this param
  • $(ConfigurationName) – Sends current configuration value; Debug or Release

You manage Major, Minor, and Revision fields of your project from project properties, Assembly Info section. Auto-increment procedure does not change Major, Minor, or Revision section of the version. It only updates Build part of project version. If you want to reset/renew build number, simply update the build field in File Version section of Assembly Information of project properties. The next auto-increment will take this new number as the base for next increment.

I hope you find this utility useful and productive.

Feedback + Follow = Fuel.

Happy F6-ing.