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

Increment File and Product Version Number - Multiple IDE

, 21 Oct 2008
Rate this:
Please Sign up or sign in to vote.
An add-in to automatically increment the FileVersion and ProductVersion fields in your application's resource file. Works in VC6 and VS2005, and probably all versions in between.

Introduction

This add-in replaces the add-in I provided a few years ago for use with Visual Studio 6. The previous add-in was based on an article by Mihai Filimon 'Increment Private Build Number'. This new add-in uses the core code of the previous add-in to increment the file and product versions in the rc and/or rc2 resource files. I have enhanced things slightly:

  • Multi-IDE compatible. I have verified that it works in VC6, VC7.1 (VS2003), VC8 (VS2005) and VC9 (VS2008). I would imagine that it works for VC7.0 (VS2002). The installer registers the add-in for use by VC6, VC7.0, VC7.1, VC8, and VC9. It kind of works in VC9 although some users have reported problems:
    1. If the VERSIONINFO block is in the .rc file, then VC9 reports that the resources have been changed externally, and do you wish to reload. Saying yes causes VC9 to crash. I have verified this, and very quickly moved my VERSIONINFO block(s) to the .rc2 file. I think this is a problem in VC9 and not my add-in Smile | :) .
    2. Manual increment works, but auto-increment does not — I have tested projects where the VERSIONINFO block is in the .rc2 file and it works for me. (This should now work because I have fixed the CBuildEventsSink class implementation of the EnvDTE::_dispBuildEvents interface.)

    I would appreciate any feedback from users of VC7.0 as I have not tested it in this IDE.

  • The file and product versions are made up of four groups of numbers — the major version, minor version, revision, and build number. (Some people may name these differently — but the concept is important here, not the naming convention. What's in a name, after all?) Anyway, the previous release of the add-in was restricted to incrementing the last number in this group. This new add-in allows you to choose which number to increment.
  • Added the option to enable/disable the add-in.
  • Added the option to only increment the version of the StartUp project. This is not applicable to VC6 as the add-in only increments the Active project anyway.
  • Added the option to increment the version even if there were build errors. The default is to not increment.
  • If you choose to increment the major version, minor version, or revision, you are given the option to 'reset' the lower numbers to their starting values. E.g., if you choose to increment the minor version, you may choose to reset the lower digits so that the revision is reset to 0 and the build number is reset to 1.
  • If you have chosen to increment the major version, minor version, or revision, you may also choose, after one increment, to revert to auto-incrementing the build number.
  • I have also added in the PrivateBuild and SpecialBuild entries of the version block, which will be incremented similar to the ProductVersion and FileVersion entries.
  • I have added options to increment all or none of these four fields, or any combination in between.

Background

Having migrated from VC6 to VC8 (and now VC9), I was disappointed to see that my original IncVersion add-in, which had served me for nigh on 4 years, was not compatible with VC8. I tried to find a replacement, but none was really forthcoming, and suffered minor niggles etc. So, I decided to to code it myself.

I was very fortunate to stumble upon a most excellent article by sp1ff, Common Add-Ins. Great! Now, I could update my add-in and it will work in both my IDEs. After a bit of jiggery-pokery, I present to you my new, multi-IDE, slightly improved add-in. I say multi-IDE. I have obviously tried it on the two versions of Visual Studio that I have, VC6 and VC8. But due to the excellence of sp1ff's article, I have no doubt it will work for all versions in between. Unless I've messed up somewhere. (Note that most of the code is sp1ff's, and all his source files contain the required comment block to reflect this.)

Using the Add-In

Installation

I have included a setup.exe which, when run, will install the add-in DLL and its satellite UI DLL in a directory of your choosing. The second part of the install makes the required registry modifications to 'register' the add-in with VC6, VC7.0, VC7.1, VC8, and VC9.

Uninstallation will remove the DLLs and clean up the registry.

Incrementing

The add-in features a toolbar with two buttons. One to perform a manual version increment, the other to configure which number in the version group to increment.

Toolbar in VC6

IncVersion in VC6

Toolbar in VC8

IncVersion in VC8

Probably, more usefully, the selected version number is also automatically incremented every time the project/solution is built. For VC6, this is only the active project. For VC8, it is the active project with all its dependencies.

Note: When performing a manual increment using the toolbar Increment button, only the active project's version number is incremented. This is true for both VC6 and VC8.

Note: For both versions, the version number is incremented whether the source files have changed or not. Depending on the chosen option, if there are any errors in a project compile, the number which was incremented is reverted back to its original value.

Why increment first then if there were build errors? The increment function is called when the build is started and not when the build is completed, so that the new version number is compiled into the resulting object. Depending on the chosen option, any errors which may occur will cause the number to be decremented again.

This updated add-in parses the project file (.dsp/.vcproj) of the project(s) being incremented for all the .rc and .rc2 files it specifies. It is not therefore limited to .rc and .rc2 files having to reside in the project directory or its /res sub-directory. It will disregard any non-C++ projects not having the .dsp/.vcproj project filename extension.

Warnings

  • If no resource files are found for a project, a warning message is displayed. This can be switched off, if desired.
  • If doing a manual increment using the toolbar Increment button, a message box is displayed.
  • If the increment occurs as part of a project compilation, the warning is written to the Output window of Visual Studio.
  • For VC6, this is on the Macro tab of the Output window. For VC8, this is in the IncVersion pane of the Output window.
  • A similar warning is displayed if one or more .rc/.rc2 files are found but none contain a VERSIONINFO block.

VC6 - no resource files found warning message

VC6 - no resource files found warning message

VC6 - no VERSIONINFO block found warning on the Macro tab of the Output window

VC6 - no VERSIONINFO block found warning on the Macro tab of the Output window

VC8 - no VERSIONINFO block found warning message

VC8 - no VERSIONINFO block found warning message

VC8 - no VERSIONINFO block found warnings and no resource files found warning in the IncVersion pane of the Output window

VC8 - no VERSIONINFO block found warnings and no resource files found warning in the IncVersion pane of the Output window

If the file or product version contains an asterisk character '*' in place of the number that is about to be incremented, the number is reset to 1 after IncVersion does its stuff.

IncVersion is able to increment multiple version blocks in both the .rc and .rc2 files at the same time (even if they are commented out!). And, there can be multiple language entries in a version block. All will be incremented.

The numbers in a version group are separated by a comma or a full-stop (a period in U.S. parlance). IncVersion is able to cope with one and/or the other in a single entry for file or product version, and can also cope with a mixture of these delimiters in the same group.

Thus:

VALUE "FileVersion", "4, 3, 1, 409\0"

VALUE "ProductVersion", "4. 3. 1. 409\0"

is okay.

VALUE "FileVersion", "4. 3, 1, 409\0"
VALUE "ProductVersion", "4. 3, 1. 409\0"

is okay too!

Finally, it doesn't matter about spaces between the digit groups, they are ignored. So FILEVERSION 4,3,1,409 is the same as FILEVERSION 4, 3,1 ,409.

Configuration

The add-in incrementing can be turned off by unchecking the 'Enable' checkbox.

By default incrementing is done if there were no builds errors. The option can be set to increment no matter what the build outcome by unchecking the 'Don't Increment If Build Errors' checkbox.

For VC7 onwards, you can choose to increment the version of all of the projects in the Active Configuration. Or to only increment the version of the StartUp project, check the 'Active/Startup Project Only' checkbox.

For all IDEs, you can select which version fields to increment — FileVersion, ProductVersion, PrivateBuild, and/or SpecialBuild.

You can change which number is incremented by clicking the Configuration button. A new dialog appears in VC6, the Options dialog appears in VC8.

VC6Options1.png

Options in VC6

VC8Options1.png

Options in VC8

Here, the add-in is enabled, all projects in the Active Configuration will be incremented, only projects with no build errors will be incremented, all four version fields are selected for incrementing, and the build number is selected for incrementing.

If a different digit is chosen, then you are presented with two more options.

VC6Options2.png

More options in VC6

VC8Options2.png

More options in VC8

Here, the VC6 add-in is configured to increment the major version once, and then to revert incrementing the build number. The VC8 add-in is configured to increment the minor version, resetting the revision (back to 0) and the build number (to start again at 1). It will also revert to incrementing the build number once the minor version has been incremented. It has also been configured to only increment the FileVersion and ProductVersion fields, and only the Active/Startup project.

Both IDEs have been configured to increment the version even if there were build errors in any of the projects.

If the 'Revert' check-box is left unticked, the add-in will continue to increment the last chosen digit. In our examples, the VC6 add-in would continue to increment the major version, and the VC8 add-in would continue to increment the minor version.

The last 'Display Warnings' check box determines whether or not a message is displayed (via a message box or to the Output window.) Untick it if you do not wish to see these warnings.

The Installer

This add-in is deployed using Jordan Russell's excellent Inno Setup. VC8 lacks a dedicated add-in deployment wizard, and I couldn't be bothered to work out what went where etc. So, I went for an approach I am very familiar with, and deployed the two DLLs using Inno setup. The second half of the install script then runs the various rgs files to register the add-in for the different IDEs. Uninstallation removes the DLLs and cleans up the registry. Wink | ;)

Request

Since I have not tested this on VC7.0, I would be very interested to know whether it does actually work in that IDE.

Of course, if you encounter any problems, then please post a message.

History

  • 11 March 2008. New article submitted with IncVersion for VC6 and VC8 (tested on both).
  • 18 March 2008. Updated article to reflect new requests/functionality.
  • 19 March 2008. Updated to only increment C++ projects. Options to switch off warning messages.
  • 28 March 2008. Fix for VC7 onwards to take account of the '>' character at the end of rc/rc2 filenames in vcproj files.
  • 25 April 2008. Added incrementing of PrivateBuild and SpecialBuild. Added options to disable incrementing totally, to only increment the version of the Active/Startup Project (not relevant for VC6), and the ability to choose whether to increment FileVersion, ProductVersion, PrivateBuild, and/or SpecialBuild.
  • 2 May 2008. VC8/9 Options - automatically selects the Increment Version Add-in options entry in IDE's Tools->Options dialog. VC8 and VC9 source code solutions. Sorry, no VC7/7.1. And, obviously, no VC6 (as this has VC7+ code in it which would not compile on VC6 anyway).
  • 24 May 2008. Fixed issue for some users where the manual increment was working but the automatic increment was not. I would like to thank Josemi Antelo for helping me trace this issue. Added option to allow incrementing to be done even if there were project build errors.
  • 10 June 2008. Fix to allow for spaces within project names. Thanks go to Kevanmc for pointing this out and providing the fix.
  • 23 June 2008. Fixed uninstaller so that Toolbar is removed from various IDEs.
  • 21 July 2008. Fixed VC6 install to puts dll’s in \Program Files\Microsoft Visual Studio\Common\MSDev98\AddIns directory. This should fix the problem with the two buttons not doing anything when pressed.
  • 25 July 2008. Fixed VC6 (and probably all IDEs) to allow for multi-byte character project pathnames. My sincere thanks go to Haerim Lee for first identifying the problem and helping me to test a fix.
  • 13 September 2008. Only increment for Build/RebuildAll events, not for Clean. Thanks to I'm Pear for finding this bug.
  • 20 October 2008. Fixed situation where if you edit your resources in some way, compile and there are errors, the resource edits are lost. I have changed the internal logic so that version incrementing is done AFTER the project build has finished. Thanks again to Haerim Lee for finding this bug.

Outstanding Issues

What with trying to support so many IDEs all at once, and the more people make use of the add-in, the more minor (and some major!) bugs become apparent.

The following is a list of outstanding bugs that I am aware of, as well as any requested enhancements that I am considering/working on.

  • Assembly file incrementing — for support for managed C++, C#, VB, and J#.
  • Only increment version number if the source in a project has changed.
  • Silence the .rc reload message. (Quite a popular one this, and I can understand why.)
  • Only increment version number if the source in a project has changed.
  • Increment all projects whose source has changed in a solution/workspace when doing command line build, or when clicking increment button — not just the active project like it does now — subject to the 'Active/Startup Project Only setting.
  • Build configuration choices to decide whether to increment only debug or release, or any combination.
  • SourceSafe integration - 'nuff said!

License

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

About the Author

Jordan Walters
Software Developer (Senior)
United Kingdom United Kingdom
Ok, it's about time I updated this profile. I still live near 'Beastly' Eastleigh in Hampshire, England. However I have recently been granted a permamant migration visa to Australia - so if you're a potential employer from down under and like the look of me, please get in touch.
Still married - just, still with just a son and daughter. But they are now 8 and 7 resp and when together they have the energy of a nuclear bomb.
I worked at Teleca UK for over 8.5 years (but have now moved to TikitTFB) and have done loads of different things. Heavily involved with MFC, SQL, C#, The latest is ASP.NET with C# and Javascript. Moving away from Trolltech Qt3 and 4.
Jordan.

Comments and Discussions

 
QuestionI find a addin support VS2010. PinmemberAlberl15-May-13 18:01 
QuestionTrying to do VC10 myself - not there (yet) PinmemberButler Institute22-Aug-11 6:05 
AnswerRe: Trying to do VC10 myself - not there (yet) PinmemberJordan Walters22-Aug-11 8:33 
GeneralRe: Trying to do VC10 myself - not there (yet) PinmemberButler Institute23-Aug-11 23:49 
GeneralRe: Trying to do VC10 myself - not there (yet) PinmemberButler Institute30-Jan-12 4:24 
GeneralRe: Trying to do VC10 myself - not there (yet) PinmemberJordan Walters30-Jan-12 6:55 
GeneralRe: Trying to do VC10 myself - not there (yet) PinmemberButler Institute29-Feb-12 6:10 
GeneralRe: Trying to do VC10 myself - not there (yet) PinmemberSynetech17-Aug-12 8:33 
GeneralRe: Trying to do VC10 myself - not there (yet) PinmemberJordan Walters17-Aug-12 10:22 
QuestionIncVersion for VS2010 ? PinmemberButler Institute29-Jul-11 2:50 
AnswerRe: IncVersion for VS2010 ? PinmemberButler Institute19-Aug-11 3:53 
GeneralDebug & Release Builds Pinmembercodevisio10-Apr-11 21:17 
GeneralFeature request: Install for all users PinmemberM.Oerder15-Jun-09 0:03 
GeneralRe: Feature request: Install for all users Pinmembershiyouc19-Jan-10 17:47 
QuestionHow can I supress message "The file has been modified..." in VS9? PinmemberNikotin3321-Jan-09 22:12 
AnswerRe: How can I supress message "The file has been modified..." in VS9? PinmemberWH Tan3-Feb-09 19:16 
QuestionYour solution and SourceSafe ? ? ? Pinmemberjtabakelis13-Nov-08 5:16 
GeneralIssues with VC6/VC9 PinmemberMember 2081924-Nov-08 7:39 
AnswerRe: Issues with VC6/VC9 PinmemberJordan Walters4-Nov-08 8:22 
QuestionDoes not find my RC & RC2 files to update . . . Pinmemberjtabakelis29-Oct-08 4:49 
QuestionCan not build your solution Pinmemberjtabakelis29-Oct-08 4:36 
AnswerRe: Can not build your solution PinmemberJordan Walters29-Oct-08 11:37 
QuestionRe: Can not build your solution Pinmemberjtabakelis30-Oct-08 4:12 
AnswerRe: Can not build your solution PinmemberJordan Walters30-Oct-08 12:50 
QuestionRe: Can not build your solution Pinmemberjtabakelis31-Oct-08 4:20 
GeneralRe: Can not build your solution Pinmemberjtabakelis31-Oct-08 4:58 
AnswerRe: Can not build your solution PinmemberJordan Walters31-Oct-08 11:41 
GeneralRe: Can not build your solution Pinmemberjtabakelis3-Nov-08 9:53 
NewsRe: Can not build your solution Pinmemberjtabakelis13-Nov-08 5:19 
GeneralRe: Can not build your solution PinmemberKrishnakumartg1-Mar-10 22:30 
QuestionIs this the best approach? PinmemberJeffBilkey27-Oct-08 16:13 
AnswerRe: Is this the best approach? PinmemberCurtis J29-Oct-08 17:51 
What I'd do (now that I see your idea) is to store it in the VERSIONINFO like this:
 
2.7108.1029.156
 
Meaning version 2.71, built in 2008, October 29, and Subversion repository revision number 156. (I use an Subversion repository, and I wouldn't particularly care if the month loses the initial zero in the VERSIONINFO resource. I can always add it back in or do any other rearranging when my program displays it.) That'd be the way I'd split it up.
 
As long as you updated the repository between builds, you could have more than one build per day, even!
GeneralRe: Is this the best approach? PinmemberJeffBilkey30-Oct-08 11:51 
GeneralSome Issues with VC9 Pinmemberwmallory22-Oct-08 6:54 
GeneralRe: Some Issues with VC9 PinmemberJordan Walters29-Oct-08 11:47 
Generala bug~ PinmemberI'm Pear12-Sep-08 20:39 
GeneralProblem "rc" file located in a path with space PinmemberGuidoKuehne28-Jul-08 3:38 
NewsThings I have left to do - PLEASE READ!! [modified] PinmemberJordan Walters22-Jul-08 11:24 
GeneralIncVersion makes VC6's MSDEV.exe frozen using up 50% from dual core cpu [modified] Pinmemberehaerim21-Jul-08 1:01 
GeneralRe: IncVersion makes VC6's MSDEV.exe frozen using up 50% from dual core cpu PinmemberJordan Walters22-Jul-08 8:46 
GeneralRe: IncVersion makes VC6's MSDEV.exe frozen using up 50% from dual core cpu Pinmemberehaerim22-Jul-08 9:17 
GeneralRe: IncVersion makes VC6's MSDEV.exe frozen using up 50% from dual core cpu PinmemberJordan Walters22-Jul-08 10:50 
GeneralRe: IncVersion makes VC6's MSDEV.exe frozen using up 50% from dual core cpu Pinmemberehaerim22-Jul-08 11:35 
QuestionUn-installation Pinmemberdpilcher3-Jul-08 9:34 
AnswerRe: Un-installation PinmemberJordan Walters3-Jul-08 10:16 
NewsCommand Line/Uninstall PinmemberScott Fehr19-Jun-08 6:38 
AnswerRe: Command Line/Uninstall PinmemberJordan Walters22-Jul-08 11:06 
GeneralOptions 'Increment Version Add-In' tab not avalible in Visual C++ version 6 PinmemberKevanmc5-Jun-08 1:33 
GeneralRe: Options 'Increment Version Add-In' tab not avalible in Visual C++ version 6 PinmemberJordan Walters10-Jun-08 11:07 
GeneralRe: Options 'Increment Version Add-In' tab not avalible in Visual C++ version 6 PinmemberSean_Xu2-Jul-08 22:33 

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.140721.1 | Last Updated 21 Oct 2008
Article Copyright 2008 by Jordan Walters
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid