Click here to Skip to main content
Click here to Skip to main content

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

, 18 May 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
Implements a macro for Visual C++ .NET for automatic build number increments in VERSIONINFO definitions of project .RC files.

VERSIONINFO Sample Screenshot

Introduction

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.

Functionality

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.

Drawback

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.

History

  • 20 May 2004.

    This is the first version of IncBuildNrMacro.

License

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

Share

About the Author

Roman Komary
Software Developer (Senior)
Austria Austria
No Biography provided

Comments and Discussions

 
GeneralExtended version PinmemberGeert van Horrik28-Apr-08 1:51 
GeneralRe: Extended version PinmvpHans Dietrich24-Oct-09 20:07 
GeneralRe: Extended version PinmemberGeert van Horrik25-Oct-09 0:12 
Generalnice macro Pinmemberhedy8-Nov-07 23:00 
QuestionNot working on VS2005 PinmemberLe Pelican24-Aug-07 9:14 
GeneralRe: Not working on VS2005 PinmemberAndrewGriffin3-Apr-08 0:00 
GeneralRe: Not working on VS2005 PinmemberMember 384044725-Apr-08 5:56 
QuestionAbout Drawback PinmemberMember #58437715-Jan-07 1:34 
QuestionHow about this method about VS 2003 problem? PinmemberKamziki20-Dec-05 16:15 
AnswerRe: How about this method about VS 2003 problem? PinmemberSynetech29-May-08 11:05 
GeneralSuggestion PinmemberCorey W20-Sep-05 4:07 
AnswerRe: Suggestion PinmemberMarkus Hlacer10-May-06 19:13 
QuestionHow does Disable_IncBuildNrMacro work? PinmemberPerry Zh4-Aug-05 23:33 
AnswerRe: How does Disable_IncBuildNrMacro work? PinmemberMember 384044725-Apr-08 5:58 
GeneralResource File get Written Back PinmemberPhil Walter11-Feb-05 4:27 
GeneralRe: Resource File get Written Back PinmemberPhil Walter11-Feb-05 4:55 
GeneralA solution for VS.Net 2003 issue PinmemberAarcheliande4-Jan-05 13:33 
GeneralRe: A solution for VS.Net 2003 issue PinmemberPhil Walter2-Feb-05 23:30 
GeneralSource Safe support Pinmembermaa081518-Nov-04 0:20 
GeneralRe: Source Safe support PinmemberRoman Komary18-Nov-04 7:11 
GeneralRe: Source Safe support PinmemberAnna-Jayne Metcalfe8-Jan-05 6:40 
GeneralA method to handle the currently selected projects only Pinmembernowyouare15-Sep-04 21:43 
GeneralVisual Studio.NET 2003 issue Pinmemberbart de lathouwer15-Jun-04 0:19 
GeneralRe: Visual Studio.NET 2003 issue PinmemberRoman Komary15-Jun-04 0:41 
GeneralRe: Visual Studio.NET 2003 issue Pinmemberbart de lathouwer15-Jun-04 1:30 

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 | Mobile
Web03 | 2.8.141022.2 | Last Updated 19 May 2004
Article Copyright 2004 by Roman Komary
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid