Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / ATL
Article

Add-in for automatically incrementing build numbers in Visual Studio .NET

Rate me:
Please Sign up or sign in to vote.
2.55/5 (22 votes)
27 May 20033 min read 125.1K   470   31   50
Finally, an add-in that increments build number for VC++.NET !

Introduction

The most convenient method I find for automatically incrementing project build numbers for Visual C++ projects is through an add-in that modifies the build number on each successful release build. I found an add-in for doing that at CodeGuru, but it only works for Visual Studio 6.0. I searched a long time for a similar add-in written for Visual Studio .NET but haven't found any. So I wrote one myself, after I did a few days of research about Visual Studio Automation Model.

Advantages of using an add-in over using macros or separate executables:

The first advantage is seamless integration with Visual Studio .NET, thus is not necessary to make custom build steps, pre-link steps or otherwise trigger the build number incrementing. The main advantage of using an add-in is, it uses the Visual Studio .NET automation code model to make modifications to files, thus the development environment is "aware" of the changes and manages them better than an external solution.

So, what does the add-in do ?

On each successful build of a project on a release configuration, the add-in searches for a file included in the project called version.h. Then it searches for one or all of the following macros and modifies their contents in a way described below. The macros that should be present in version.h are (at least one of them is required):

  • FILE_VERSION
  • PRODUCT_VERSION
  • FILE_VERSION_STR
  • PRODUCT_VERSION_STR

The macros can be placed anywhere in the file. The file can contain other things besides these macros. An example of version.h file:

#define FILE_VERSION         1,0,0,1
#define PRODUCT_VERSION      1,0,0,9
#define FILE_VERSION_STR     "1, 0, 0, 1\n"
#define PRODUCT_VERSION_STR  "1, 0, 0, 9\n"
<!-- end the block of source code -->

After a successful project build on a release configuration, version.h will become:

#define FILE_VERSION         1,0,0,2
#define PRODUCT_VERSION      1,0,0,10
#define FILE_VERSION_STR     "1, 0, 0, 2\n"
#define PRODUCT_VERSION_STR  "1, 0, 0, 10\n"
<!-- end the block of source code -->

Tip: All of these macros can contain any type of string containing at least a decimal number. Only the last number on that string will be incremented. For example, if FILE_VERSION is 1.2, then after build, it will become 1.3.

OK, so how do you use the add-in to increase the build number contained in the version resource?

There is an article on Microsoft Support found here that explains how to do that in a safe way. Basically, you have to cut the version resource from your .rc file and paste it to your .rc2 file. Then replace the values of FILEVERSION and PRODUCTVERSION statements with FILE_VERSION and PRODUCT_VERSION. Then you have to include the file version.h at the top of the version resource.

Add-in installation

  1. Save the file autobuildnumber.dll in a directory.
  2. Run command "regsvr32 autobuildnumber.dll" from the add-in's directory.
  3. Double click the file autobuildnumber.reg.
  4. Go to the Visual Studio .NET IDE, and from Tools->Add-in Manager menu, check the box "AutoBuildNumber". You can also check the boxes "Startup" and "Command line".
  5. Include a version.h file (containing the above macros) in your project.
  6. That's all.

Notes:

After successfully incrementing build numbers, the add-in displays an output message in the build output window, indicating success. If the version.h file is under source control and is not checked out, the add-in displays an error message in the build output window describing the error. In that case, the build number is not incremented.

The source files are not included. The add-in was built with Visual Studio .NET 2003 and tested on Visual Studio .NET 2002 and 2003. Please e-mail me for support information and source files information.

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
Web Developer
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerRe: What is updated? Pin
biometrics7427-Jan-05 14:18
biometrics7427-Jan-05 14:18 
GeneralRe: What is updated? Pin
Member 6339837-Feb-05 22:25
Member 6339837-Feb-05 22:25 
GeneralRe: What is updated? Pin
biometrics749-Feb-05 15:28
biometrics749-Feb-05 15:28 
Generalerror on tool enable Pin
Anonymous27-May-03 23:31
Anonymous27-May-03 23:31 
GeneralRe: error on tool enable Pin
Catalin Stavaru28-May-03 0:24
Catalin Stavaru28-May-03 0:24 
GeneralRe: error on tool enable Pin
jlatorref27-Sep-04 3:57
jlatorref27-Sep-04 3:57 
GeneralRe: error on tool enable Pin
bbczeuz17-Jul-05 3:22
bbczeuz17-Jul-05 3:22 
GeneralSources, sources!!!! Pin
paul_alkhimov@yahoo.com27-May-03 22:23
paul_alkhimov@yahoo.com27-May-03 22:23 
GeneralRe: Sources, sources!!!! Pin
Catalin Stavaru28-May-03 1:00
Catalin Stavaru28-May-03 1:00 
GeneralRe: Sources, sources!!!! Pin
Herbert Yu21-Jun-04 13:49
Herbert Yu21-Jun-04 13:49 
QuestionIs it suit for vc6? Pin
liuty200616-May-03 4:58
liuty200616-May-03 4:58 
AnswerRe: Is it suit for vc6? Pin
KlausR3-Jun-03 10:22
KlausR3-Jun-03 10:22 
GeneralGood Work Pin
rromerot15-May-03 2:21
rromerot15-May-03 2:21 
GeneralPost-increment Pin
JohnAtTopcon14-May-03 22:57
JohnAtTopcon14-May-03 22:57 
GeneralRe: Post-increment Pin
Catalin Stavaru15-May-03 0:49
Catalin Stavaru15-May-03 0:49 
GeneralRe: Post-increment Pin
Mike Klimentiev27-May-03 9:02
Mike Klimentiev27-May-03 9:02 
GeneralRe: Post-increment Pin
Catalin Stavaru28-May-03 0:16
Catalin Stavaru28-May-03 0:16 
GeneralRe: Post-increment Pin
Mike Klimentiev27-May-03 9:15
Mike Klimentiev27-May-03 9:15 
QuestionHow to semi-automatically increment build numbers? Pin
Anatoly Ivasyuk14-May-03 6:12
Anatoly Ivasyuk14-May-03 6:12 
AnswerRe: How to semi-automatically increment build numbers? Pin
lvidaguren20-May-03 8:55
lvidaguren20-May-03 8:55 
QuestionNo Sources. Why? Pin
Uwe Keim14-May-03 5:13
sitebuilderUwe Keim14-May-03 5:13 
AnswerRe: No Sources. Why? Pin
Catalin Stavaru15-May-03 3:20
Catalin Stavaru15-May-03 3:20 
GeneralRe: No Sources. Why? Pin
rromerot15-May-03 7:43
rromerot15-May-03 7:43 
GeneralRe: No Sources. Why? Pin
rromerot15-May-03 7:44
rromerot15-May-03 7:44 
GeneralRe: No Sources. Why? Pin
Catalin Stavaru15-May-03 9:51
Catalin Stavaru15-May-03 9:51 

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.