Click here to Skip to main content
15,446,510 members
Articles / Programming Languages / Visual Basic
Posted 18 May 2004


28 bookmarked

Increase Build Numbers in Visual C++ .NET using Macros

Rate me:
Please Sign up or sign in to vote.
4.41/5 (19 votes)
18 May 2004CPOL4 min read
Implements a macro for Visual C++ .NET for automatic build number increments in VERSIONINFO definitions of project .RC files.

VERSIONINFO Sample Screenshot


There are many solutions out there for automatic build number increment support. Many are meant for VC6. The ones I found for Visual C++ .NET are commonly using add-ins for the DevStudio. Usually, a good and very integrated method, they all have the disadvantage of inflexibility. They require some sort of separate header file with defines that have to be used in the project's resource file. And if you want to adopt the add-in's functionality somehow to fit your needs more closely, it often is not possible to get the source code of the add-in.

So, I tried to find a macro for VC.NET instead of add-ins, unfortunately without success. That's the reason why I decided to write my own macro and offer it to the public. You can simply change it according to your needs, or take it as a template sample for your own macro implementations.


My macro implementation reacts on the DevStudio's event when a build starts. The macro scans resource files (.RC extension only) in all projects of the current solution. All files not having the extension .RC will be skipped.

In a resource file, the macro will search for all VERSIONINFO definitions, and inside there, it will increment the build numbers for all 4 statements FILEVERSION, PROJECTVERSION, "FileVersion" and "ProjectVersion". It will handle multiple language blocks, too (if present).

To disable parsing a .RC file, specify the following line of code somewhere in the .RC file:

#define Disable_IncBuildNrMacro

If you don't specify this line or if it is remarked out, then the .RC file will be parsed and build numbers will be incremented.

DevStudio language related notes:

At the start of a build process, the IncBuildNr macro will output information messages about success or failure of manipulating the .RC files or when .RC files have been skipped. The messages will be posted into the output-window's Build pane where the compiler inserts its own progress information, too. The macro is implemented for English versions of the DevStudio. If your DevStudio has a different language, it can be, that the macro does not find the correct output-window-pane. This can happen, because the macro simply opens a pane named "Build". If in your DevStudio, the output-window-pane for build progress information is named differently, it is recommended to change the pane name in the macro sources accordingly (in module EnvironmentEvents, in function BuildEvents_OnBuildBegin()).

Further description you can find in the macro sources themselves (when you open it in the DevStudio's Macro Editor).

Installation Instructions

First, go to the location of your Visual Studio macros. By default, this is Personal\Visual Studio Projects\VSMacros. In there, create a subdirectory named IncBuildNrMacro and copy the file IncBuildNrMacro.vsmacros in there.

Now, open the VC++ .NET DevStudio, open the Macro Explorer, right click on the root item "Macros", and select "Load Macro Project". Open IncBuildNrMacro.vsmacros. A warning appears informing you that the loaded macro contains event handling code. Select "Enable event handling code", and press OK. This is required, otherwise the macro would not react on build starts.

That's it. The next time you build a project, the IncBuildNr macro will be invoked automatically.

Uninstallation Instructions

In VC++ .NET DevStudio, go to the Macro Explorer, right click on "IncBuildNrMacro" and select "Unload Macro Project". You can delete the IncBuildNrMacro.vsmacros file now, if you like to.

Usage in your C++ project(s)

To query the VERSIONINFO definition contents in your application at runtime, use GetFileVersionInfo() and related functions.


All .RC files in all Projects of the current Solution will be handled at once. Even if the user wants to build only one specific project within the current solution, the macro will increment build numbers of all the projects in the solution. I did not find a way (yet) to detect which projects are being compiled. Although this can be seen as a drawback, it can also be seen as an advantage: all the build numbers in the projects will be handled always at the same time. So, the build numbers remain accurate and equal over all projects.

But nevertheless, if you find a way to detect specific projects being built, let me know.

Further, whenever a project's resources have been opened in the DevStudio either in the Resource View (the tree view) or in resource editing windows such as the dialog editor, the icon editor etc., the macro first will close all these windows so that it can access the contents of the resource file. (Exception: the Resource View Tool window will stay present.) It may be annoying to see all the resource windows disappear every time a build process is started. But again, I did not find any other solution for this problem yet. Maybe you have a better idea. If so, please let me know.


  • 20 May 2004.

    This is the first version of IncBuildNrMacro.


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

Written By
Software Developer (Senior)
Austria Austria
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

GeneralExtended version Pin
Geert van Horrik28-Apr-08 1:51
MemberGeert van Horrik28-Apr-08 1:51 
GeneralRe: Extended version Pin
Hans Dietrich24-Oct-09 20:07
mentorHans Dietrich24-Oct-09 20:07 
GeneralRe: Extended version Pin
Geert van Horrik25-Oct-09 0:12
MemberGeert van Horrik25-Oct-09 0:12 
Generalnice macro Pin
hedy8-Nov-07 23:00
Memberhedy8-Nov-07 23:00 
QuestionNot working on VS2005 Pin
Le Pelican24-Aug-07 9:14
MemberLe Pelican24-Aug-07 9:14 
GeneralRe: Not working on VS2005 Pin
AndrewGriffin3-Apr-08 0:00
MemberAndrewGriffin3-Apr-08 0:00 
GeneralRe: Not working on VS2005 Pin
Member 384044725-Apr-08 5:56
MemberMember 384044725-Apr-08 5:56 
QuestionAbout Drawback Pin
Member 58437715-Jan-07 1:34
MemberMember 58437715-Jan-07 1:34 
QuestionHow about this method about VS 2003 problem? Pin
Kamziki20-Dec-05 16:15
MemberKamziki20-Dec-05 16:15 
AnswerRe: How about this method about VS 2003 problem? Pin
Synetech29-May-08 11:05
MemberSynetech29-May-08 11:05 
GeneralSuggestion Pin
Corey W20-Sep-05 4:07
MemberCorey W20-Sep-05 4:07 
AnswerRe: Suggestion Pin
Markus Hlacer10-May-06 19:13
MemberMarkus Hlacer10-May-06 19:13 
QuestionHow does Disable_IncBuildNrMacro work? Pin
Mingliang Zhu4-Aug-05 23:33
MemberMingliang Zhu4-Aug-05 23:33 
AnswerRe: How does Disable_IncBuildNrMacro work? Pin
Member 384044725-Apr-08 5:58
MemberMember 384044725-Apr-08 5:58 
GeneralResource File get Written Back Pin
Phil Walter11-Feb-05 4:27
MemberPhil Walter11-Feb-05 4:27 
GeneralRe: Resource File get Written Back Pin
Phil Walter11-Feb-05 4:55
MemberPhil Walter11-Feb-05 4:55 
GeneralA solution for VS.Net 2003 issue Pin
Aarcheliande4-Jan-05 13:33
MemberAarcheliande4-Jan-05 13:33 
GeneralRe: A solution for VS.Net 2003 issue Pin
Phil Walter2-Feb-05 23:30
MemberPhil Walter2-Feb-05 23:30 
GeneralSource Safe support Pin
18-Nov-04 0:20
suss18-Nov-04 0:20 
GeneralRe: Source Safe support Pin
Roman Komary18-Nov-04 7:11
MemberRoman Komary18-Nov-04 7:11 
GeneralRe: Source Safe support Pin
Anna-Jayne Metcalfe8-Jan-05 6:40
MemberAnna-Jayne Metcalfe8-Jan-05 6:40 
GeneralA method to handle the currently selected projects only Pin
nowyouare15-Sep-04 21:43
Membernowyouare15-Sep-04 21:43 
GeneralVisual Studio.NET 2003 issue Pin
Piet Bibber15-Jun-04 0:19
MemberPiet Bibber15-Jun-04 0:19 
GeneralRe: Visual Studio.NET 2003 issue Pin
Roman Komary15-Jun-04 0:41
MemberRoman Komary15-Jun-04 0:41 
GeneralRe: Visual Studio.NET 2003 issue Pin
Piet Bibber15-Jun-04 1:30
MemberPiet Bibber15-Jun-04 1:30 

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.