Friday, August 4, 2006

HOWTO: Auto-Increment the Version in Visual C# Express

One of the features that I miss the most when I am working in Visual C# 2005 Express Edition is the possibility to auto-increment the version number for each build. Below, I will explain how to get around the limitation and add this functionality to the stripped down Express Edition of Microsoft's Visual Studio development environment.

The solution comes from CodeProject user PIEBALDconsult's Versioner project. His C# class increases the revision number of the AssemblyVersion, given the path to the file where it resides (typically AssemblyInfo.cs). Since PIEBALDconsult only provides the source code I took the liberty of compiling it into a .NET 2.0 executable, which can be downloaded from here (ZIP). The steps necessary for enabling auto-increment are listed below:

  1. Download and extract Versioner.exe from the ZIP archive to the project directory where you want to enable the auto-increment feature.
  2. Right click on the project in Visual C# 2005 Express Edition and choose Properties.
  3. Click Build Events.
  4. In the text box where it says Pre-build event command line enter:
$(ProjectDir)Versioner.exe $(ProjectDir)Properties\AssemblyInfo.cs        

Now, each time you compile the project, the AssemblyVersion's revision will increase by one.

1 comment:

  1. One small note... i've noticed that if the project location and/or the Versioner.exe is located in a directory with spaces you should use " in order to run properly. e.g.: "$(ProjectDir)Versioner.exe" "$(ProjectDir)Properties\AssemblyInfo.cs".

    Other thing... I have a solution with many projects so instead of copying the versioner.exe to all projects root I used the project solution for the versioner location. e.g: "$(SolutionDir)Versioner.exe" "$(ProjectDir)Properties\AssemblyInfo.cs".

    ReplyDelete