Introduction
There are many articles and applications posted here, but I couldn't find one that could do what I wanted. I don't want to add any plug-in to Visual Studio, or modify any .rc files that the IDE should maintain and modify. I want to add more version info like build date. Some of the solutions given here are good but are not complete. They represent only a starting point to my solution.
Solution
The goal is to add dynamic version numbers in the .rc file of your project and a build a date string. Starting from the point that the .rc file of your project supports #include
directives, I made the following:
- Defined some constants:
#define VERSION_MAJOR 4
#define VERSION_MINOR 5
#define VERSION_BUILD 46
#define VERSION_QFE 11
#define VERSION_BUILD_DATE "24/05/2005"
#define VERSION_BUILD_TIME "08:37:55UTC"
#define _STR(x) #x
#define STR(x) _STR(x)
#define VERSION_NUMBER VERSION_MAJOR,VERSION_MINOR,
VERSION_BUILD,VERSION_QFE
#define VERSION_STRING STR(VERSION_MAJOR) "." STR(VERSION_MINOR) "." \
STR(VERSION_BUILD) "." STR(VERSION_QFE)
#define VERSION_COMPANY ""
#define VERSION_COPYRIGHT "(C) Gugulea 2005"
#define VERSION_TRADEMARK ""
#define VERSION_BUILD_DATE_TIME VERSION_BUILD_DATE " - " \
VERSION_BUILD_TIME
The version of a file looks like this: 4.5.46.11. The numbers represent the major, minor, build and qfe numbers of your product. I chose to modify the build number, though my solution easily supports modifications of any of the numbers and even adds more.
- Put all these
#define
s in a version.h file, which I'll include in the .rc file: #ifndef _MAC
#include "version.h"
.........................
#endif
because only some of these numbers/strings are modified, I have separated them into version.ver:
#define VERSION_MAJOR 4
#define VERSION_MINOR 5
#define VERSION_BUILD 46
#define VERSION_QFE 11
#define VERSION_BUILD_DATE "24/05/2005"
#define VERSION_BUILD_TIME "08:37:55UTC"
and version.h:
#include "version.ver"
#define _STR(x) #x
#define STR(x) _STR(x)
#define VERSION_NUMBER VERSION_MAJOR,VERSION_MINOR,
VERSION_BUILD,VERSION_QFE
#define VERSION_STRING STR(VERSION_MAJOR) "." STR(VERSION_MINOR) "." \
STR(VERSION_BUILD) "." STR(VERSION_QFE)
#define VERSION_COMPANY ""
#define VERSION_COPYRIGHT "(C) Gugulea 2005"
#define VERSION_TRADEMARK ""
#define VERSION_BUILD_DATE_TIME VERSION_BUILD_DATE " - " \
VERSION_BUILD_TIME
version.h includes version.ver and is included by the .rc file, therefore instead of adding the version numbers directly into the .rc files I have separated them into more files. The only file that will be modified is the version.ver file, which is pretty simple and easy to maintain and modify, and it will be the only one that will be automatically modified on each build.
The .rc file will look like this:
#ifndef _MAC
#include "version.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_NUMBER
PRODUCTVERSION VERSION_NUMBER
...
VALUE "Build Date", VERSION_BUILD_DATE_TIME "\0"
VALUE "CompanyName", VERSION_COMPANY "\0"
VALUE "FileVersion", VERSION_STRING "\0"
VALUE "LegalCopyright", VERSION_COPYRIGHT "\0"
VALUE "LegalTrademarks", VERSION_TRADEMARK "\0"
VALUE "ProductVersion", VERSION_STRING "\0"
...
#endif
The "Build Date" string is added manually and will appear in the version tab of the module, DLL or EXE.
Now there is another problem with Visual C++ and .rc files. If you modify some of the resources or add new resources to your application it will overwrite the version strings. Therefore you can put all the previous part in a .rc2 file, which you can include in the .rc file.
That's all, the two files that you have included in the resource files are: version.h and version.ver. The last one will be modified by an external application, whereas the resource files are not touched. The file makeversion.exe will update the VERSION_BUILD_DATE
and the VERSION_BUILD_TIME
values to the current ones and will increment the VERSION_BUILD
number. You can modify it to update any of the numbers in version.ver, like for example VERSION_MINOR
.
- Run the makeversion tool at build time. For VC6 you have to add it in the "Pre-link step" entry of your project.
For Release:
makeversion.exe /inc version.ver
rc.exe /l 0x409 /fo"Release/cdcdcd.res" /d "NDEBUG" "C:\cdcdcd.rc"
For Debug:
makeversion.exe version.ver
rc.exe /l 0x409 /fo"Debug/cdcdcd.res" /d "_DEBUG" "C:\cdcdcd.rc"
The rc
command can be found in the Build log of the project.
The /inc option will increment the build number and should only be added in the release version of your product. makeversion.c is written in C; version.ver file contains the standard #define
directives and doesn't support any comments; empty lines are also ignored; /h or /? options in the command line shows more parameters. If version.ver file does not exist it will be automatically created. If it is empty it will be filled with default version 1.0.0.0 and the current time and date.