Visual Studio.NET Add-In for Incrementing Project Build Numbers

Environment: Visual Studio.NET 2002, Visual Studio.NET 2003

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 the 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 incrementation. 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. Here is an example of a 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"

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"
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, after the build it will become 1.3.

Okay, 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 the FILEVERSION and PRODUCTVERSION statements with FILE_VERSION and PRODUCT_VERSION. Then, you have to include the "version.h" file at the top of the version resource.

Add-In Installation

  1. Save the file "autobuildnumber.dll" in a directory.
  2. Run the "regsvr32 autobuildnumber.dll" command from the add-in's directory.
  3. Double click the autobuildnumber.reg file.
  4. Go to the Visual Studio.NET IDE, and from the Tools->Add-in Manager menu, check the "AutoBuildNumber" box. You also can 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.

Downloads

Download add-in - 68 Kb


Comments

  • VS2005 No Go

    Posted by Wiccaan on 12/14/2006 07:29am

    I know this article is pretty old, just informing the author, if they are still around and haven't noticed yet, that this does not work VS2005 =/

    Reply
  • Can you email me the source

    Posted by Legacy on 02/12/2004 12:00am

    Originally posted by: FilbertFox

    I like your add-in, can you email me the source code or release it on this site? I need to add a few features of my own, so the source will save me alot of time.

    Reply
  • Please provide source code for your addin

    Posted by Legacy on 05/20/2003 12:00am

    Originally posted by: logan dugenoux

    The interesting thing is mainty how to build addins for Visual Studio, not the build number...

    Reply
  • Source code is more welcome

    Posted by Legacy on 05/16/2003 12:00am

    Originally posted by: typetype

    Do you notice that almost all projects in codeguru are coming as both binary and source code?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds