Click here to Skip to main content
13,700,462 members
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 27 Jun 2007
Licenced CPOL

Auto Increment Microsoft Build Task

, 27 Jun 2007
Rate this:
Please Sign up or sign in to vote.
Auto Increment Assembly Version in a Microsoft Build Task


This article describes how to auto increment the build/revision numbers in your assembly as a build task.


I originally got the source code from an article on this site by Dave Gallant. He did an excellent job of implementing a solution that worked I originally read from this blog. Dave's original code worked as stated, but I wanted more. Specifically, I used to use a project called UpdateVersion some years ago that did the same thing but used the command line. I wanted to combine the power of options included with UpdateVersion into a MSBuild Task. The results of that are included here.


  1. AutoIncrement searches its input for a .NET AssemblyVersion attribute and calculates a new version number using one of several algorithms. 
  2. AutoIncrement calculates and outputs new version numbers using one of several algorithms. You can use it with Visual Studio .NET to update your AssemblyInfo.* file on every build.
  3. AutoIncrement will calculate a new revision number only or it can calculate a new build number and a new revision number at the same time.
  4. AutoIncrement can calculate the build number by incrementing the existing build number or it can calculate the build number based on the project start date. 
  5. AutoIncrement can calculate the revision number by incrementing the existing revision number or it can calculate the revision number based on the number of seconds since midnight.

Using the Code

  1. Install the AutoIncrementBuildTask.dll into your GAC. That way you don't have to copy it into the same folder that your project file is in.

  2. In your project file (vbproj or csproj), add this line...

    <UsingTask TaskName="BuildTasks.IncrementBuildNumber" 
      AssemblyName="AutoIncrementBuildTask, Version=, Culture=neutral,
      PublicKeyToken=c77dd5dca239f8e6" />  

    ... between the <Project> tag and the first <PropertyGroup> tag. For example, the first three lines of your project should look like this:

    <Project DefaultTargets="Build" 
    <UsingTask TaskName="BuildTasks.IncrementBuildNumber" 
      AssemblyName="AutoIncrementBuildTask, Version=, Culture=neutral,
      PublicKeyToken=c77dd5dca239f8e6" />
  3. Now find the <Target Name="BeforeBuild"></Target> tags and add this between them.

      BuildOptions="-s 2006-05-31 -b MonthDay -r Fixed"/> 

    IMPORTANT! - Make sure the path to your assembly file is CORRECT!

    $(MSBuildProjectDirectory) means the folder your project file is in, so it will be relative to that. In my case, it's in the root folder, and since it's a C# app, it's the AssemblyInfo.cs file.

  4. Save the project and load it. The major and minor numbers will stay the same, and the Build and Revision will be updated, depending on your options above.

Points of Interest

I default on fixing the revision (-r Fixed) and increment the build (-b Increment). In my projects, a lot of assemblies reference each other and are copied into a common build folder.
A common build folder plays nicely with Visual Studio, but you have to add the path to the registry like this:


Here my default build directories are c:\usr\Build\Lib\Net-2.0 or Net-1.1 depending.


<IncrementBuildNumber  BuildOptions="-b Increment">
<IncrementBuildNumber  BuildOptions="-b Increment -r Increment">
<IncrementBuildNumber  BuildOptions="-b MonthDay -s 2002-11-23">
<IncrementBuildNumber  BuildOptions="-b MonthDay -s 11/23/2002">
<IncrementBuildNumber  BuildOptions="-p">
<IncrementBuildNumber  BuildOptions="-b BuildDay">
<IncrementBuildNumber  BuildOptions="-b Increment -r Fixed">
<IncrementBuildNumber  BuildOptions="-b BuildDay">  


  • Initial release which includes code from UpdateVersion v1.2 and Dave Gallant's original implementation. Great job to both Dave and the authors of UpdateVersion.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer myspace
United States United States
Its a passion, why else would we be doing this? Everyday it feels like gold fever, wouldn't you agree? With the boom of the internet and an ever decreasing world, programming today feels a lot like the wild wild west of the past. Its so wide open, filled with tremendous opportunities. Its more than a passion, its a forming of the ideas that later generations will use.

With over ten years experience, I've earned the right to say that. The majority of my career has focused on enterprise application development. I earned my BS in CS from UCI, hi everybody. My fondest memories as a child was working with the 8mhz IBM AT my daddy brought home for us. Yeah, I'm a geek, and proud of it. We're at the forefront of something huge, enjoy it.

You may also be interested in...


Comments and Discussions

QuestionCan I use the auto increment build task for fileVersion or productVersion ? Pin
bigbits5-Mar-13 5:21
memberbigbits5-Mar-13 5:21 
GeneralCan't figure out what I'm doing wrong Pin
redbergy1-Dec-09 16:13
memberredbergy1-Dec-09 16:13 
GeneralRe: Can't figure out what I'm doing wrong Pin
redbergy2-Dec-09 6:10
memberredbergy2-Dec-09 6:10 
GeneralRevision number to be retained as specified Pin
vsharma11-May-09 23:37
membervsharma11-May-09 23:37 
GeneralThanks a lot Pin
zzattack18-Aug-08 12:48
memberzzattack18-Aug-08 12:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180910.1 | Last Updated 27 Jun 2007
Article Copyright 2007 by andrewcates
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid