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:
- 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 :).
- 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
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
SpecialBuild entries of the version block, which will be incremented similar to the
FileVersion entries.I have added options to increment all or none of these four fields, or any combination in between.
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
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.
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.
IncVersion in VC6
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.
- 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
VC6 - no resource files found warning message
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 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.
VALUE "FileVersion", "4, 3, 1, 409\0"
VALUE "ProductVersion", "4. 3. 1. 409\0"
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.
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.
Options in VC6
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.
More options in VC6
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.
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. ;)
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.
- 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.</a />
- 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.
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!