Click here to Skip to main content
11,805,604 members (55,758 online)
Click here to Skip to main content

Automatically Increment Build Numbers in Visual Studio 2005

, 19 Apr 2006 CPOL 63.1K 430 24
Rate this:
Please Sign up or sign in to vote.
A demonstration of how to harness the power of the DTE and macros in Visual Studio, to create a build number incrementer.


This macro automatically increments the build number of a project by one, every time a build is started.


One of my long time gripes about Visual Studio is the lack of an option to just increment the build number every time I hit the Build button. Sure, this is not the most elegant solution, but it's better than nothing. When I was originally contemplating this project, I was looking for a way to intelligently check whether the increment is warranted or not, like say in C#, I hit the Build button just to check for errors, so I might want the build to increment every time I hit F5 instead. However, there is no good way to do this using the interfaces provided by Visual Studio, so we will just have to make one.

Using the code

Download the code and extract it. Open up Visual Studio, and from the Tools menu, select Macros->Macros IDE. Under the MyMacros heading in the Macro Project Explorer, open EnvironmentEvents and copy the function from the corresponding file in the Zip. Repeat for the functions in Module1.vb in the Zip. That's all, your project build number will now be automatically incremented. The code is very heavily commented, so if you have any questions, the comments are bound to answer them.

Points of Interest

One interesting note that tripped me up is that VB sticks a comment demonstrating how to set a wildcard for the AssemblyVersion attribute. As the comment came before the actual code line, the macro would read it first and then would be unable to find the AssemblyFileVersion attribute and would error out. My solution was to have the macro check for this commented line and remove it every time the macro was run. It is a brute-force solution, but it solved the problem.

There is currently no way to turn this macro off unless you erase the event handler in EnvironmentEvents.

If you have a wildcard character (*) in the build number field, it will be automatically replaced with a 1 when the build is started.

Currently, the macro only operates on C# and Visual Basic projects, and ignores everything else. However, it would be very easy to expand the function to include your own language of choice.

To my knowledge, C++ is so different in structure from .NET that this incrementer will not work on pure C++ projects.


  • 1.0 - First release.


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


About the Author

Team Leader Prospective Software Inc.
United States United States
My name is Adam Wilson.
I am business software developer with over 7 years of VB.NET experience, starting with Visual Studio 2002 RC1. However I made the switch to C# a few years ago and I haven't looked back. I started programming in VB6 13 years ago, and have been on employed as a Senior Software Developer/IT Manager at a small ISV since 2003.

You may also be interested in...

Comments and Discussions

GeneralNumber updated too late Pin
Luke Edwards3-Feb-09 0:34
memberLuke Edwards3-Feb-09 0:34 
GeneralGoodness Gracious [modified] Pin
toddmo16-Sep-08 19:07
membertoddmo16-Sep-08 19:07 
GeneralThe event BuildEvents_OnBuildProjConfigBegin doesn't fire Pin
GiGi Abbrescia28-May-07 0:02
memberGiGi Abbrescia28-May-07 0:02 
GeneralFeature exists in VS2005 Pin
simabo5-Mar-07 1:04
membersimabo5-Mar-07 1:04 
GeneralRe: Feature exists in VS2005 Pin
mikey2225-Jun-07 6:21
membermikey2225-Jun-07 6:21 
GeneralRe: Feature exists in VS2005 (Works in VS2008 Express as well) Pin
Tyreck19-Jan-09 9:52
memberTyreck19-Jan-09 9:52 
GeneralRe: Feature exists in VS2005 Pin
AveryH9-May-09 15:15
memberAveryH9-May-09 15:15 
QuestionIncrement a Solution dosn't work?! Pin
j5136p18-Nov-06 1:34
memberj5136p18-Nov-06 1:34 
QuestionRe: Increment a Solution dosn't work?! Pin
Bellerephon8-Nov-06 7:07
memberBellerephon8-Nov-06 7:07 
QuestionRe: Increment a Solution dosn't work?! Pin
j5136p18-Nov-06 18:48
memberj5136p18-Nov-06 18:48 
GeneralNot working for me... Pin
dirigo14-May-06 2:14
memberdirigo14-May-06 2:14 
AnswerRe: Not working for me... Pin
Bellerephon15-May-06 21:54
memberBellerephon15-May-06 21:54 
GeneralRe: Not working for me... Pin
dirigo16-May-06 5:17
memberdirigo16-May-06 5:17 
AnswerRe: Not working for me... Pin
Bellerephon17-May-06 20:29
memberBellerephon17-May-06 20:29 
QuestionNot in Express versions Pin
SLURPO26-Apr-06 3:14
memberSLURPO26-Apr-06 3:14 
AnswerRe: Not in Express versions Pin
Bellerephon26-Apr-06 18:25
memberBellerephon26-Apr-06 18:25 
GeneralAutoincrementing build numbers is considered a bug in VS.NET 2003!!! Pin
performer2426-Apr-06 0:21
memberperformer2426-Apr-06 0:21 
AnswerRe: Autoincrementing build numbers is considered a bug in VS.NET 2003!!! Pin
Bellerephon26-Apr-06 18:28
memberBellerephon26-Apr-06 18:28 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151002.1 | Last Updated 19 Apr 2006
Article Copyright 2006 by Bellerephon
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid