Click here to Skip to main content
15,895,011 members
Articles / Programming Languages / XML

Auto Increment Visual Studio 2005 version build and revision number on compile time

Rate me:
Please Sign up or sign in to vote.
4.67/5 (12 votes)
10 Mar 20063 min read 277.7K   973   63  
Auto increment Visual Studio 2005 version build and revision number on compile.
Ok, I learned how to do this by trying to get BradleyB's 'How to auto-increment assembly version using a custom MSBuild taskworking
and I failed horribly.
http://weblogs.asp.net/bradleyb/archive/2005/12/02/432150.aspx

So I set out to make my own system, using what I learned about Build Tasks from the above sample.

I eventually got it working from that code, and what I learned from the source code
provided in http://blogs.msdn.com/msbuild/archive/2005/11/11/491947.aspx

While hte MSBuild Team Blog teams code worked, it overwrote the major and minor numbers
and didn't do "exactly" what I wanted... plus their source code was overly complicated.






So I wrote this dll. To get it working, do the below steps.

1. Copy the BuildTask.dll into the same folder that your project file is in. (.vbproj for vb)


2. In your project file itself add this line:

<UsingTask TaskName="BuildTasks.IncrementBuildNumber" AssemblyFile="BuildTask.dll" />

between the <Project> tag  and first <PropertyGroup> tag.

ie: the first three lines of my test project look like this:
	<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
		<UsingTask TaskName="BuildTasks.IncrementBuildNumber" AssemblyFile="BuildTask.dll" />
		<PropertyGroup>


3. Now, find hte <Target Name="BeforeBuild"></Target> tags and add this between them.
(Make sure they get uncommented if they are - the <!-- and --> tags workt he same as /* */ in c#

   <IncrementBuildNumber
     AssemblyFileLocation = "$(MSBuildProjectDirectory)\My Project\AssemblyInfo.vb">
   </IncrementBuildNumber>


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 tot hat
in my case, it's in the My Project folder, and since it's a vb app, it's the AssemblyInfo.vb



4. Save the project and load it. The major and minor numbers will will be whatever you assign in the
assembly file, but the build and revision will be overwritten.




The default that I use is   MAJOR.MINOR.Number of days since jan 01 2000.Number of times compiled today

When you run/compile the revision number increases. This will occure EVERY TIME the dll is called.
so if your visual studio calls it multiple times, your number could jump 2 or 3 or more at a time.
I don't care, so I never bothered to try to fix this.

Also, the revision number *may* not increament if you have the assembly or project properties window open
Again, I didn't care enough to fix it as it's not that big a deal.


Enjoy.

Dave Gallant
kaydeng@yahoo.ca

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions