![]() |
General Programming »
Macros and Add-ins »
Visual Studio .NET Addins
Intermediate
License: The Code Project Open License (CPOL)
Increment File and Product Version Number - Multiple IDEBy Jordan WaltersAn 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. |
C++, Windows (WinXP, Vista), Visual Studio, ATL, STL, Dev, QA
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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:
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 :).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.
PrivateBuild and SpecialBuild entries of the version block, which will be incremented similar to the ProductVersion and FileVersion entries.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.)
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.
VERSIONINFO block.



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.
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.


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.


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.
>' character at the end of rc/rc2 filenames in vcproj files.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.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 21 Oct 2008 Editor: Sean Ewington |
Copyright 2008 by Jordan Walters Everything else Copyright © CodeProject, 1999-2009 Web22 | Advertise on the Code Project |