Download demo project - 35 Kb
Updated: 09 Mar 2000. See below for updates.
This code increments the version number on each build.
After including the autobuild.dll as an Add-In for dev studio, the following happens. When you do a build, a file autobuild.h is created/updated in your project's folder.
If you want to increment your version number with each build, set the flag INCREMENT_BUILD_NUM
to true in the generated autobuild.h, AND make the file attribute for your project's .rc file to read-write.
#ifndef __AUTOBUILD_H__
#define __AUTOBUILD_H__
#define INCREMENT_BUILD_NUM TRUE
#define BUILD_NUM 2723
#endif
If the flag is true, the project's version number stored in the .rc file is incremented. If the flat is false, or the .rc file is read-only, the version number is not incremented. That is the extent of the change brought about by including the add-in in the project.
In my project, I also use Manuel Laflamme's code from the CodeGuru.com site, to get the version number from the .rc file and display it in the help-about dialog box. Here is the code snippet that is used to get the version number within the code.
dlgAbout.cFileVersion.Open(m_sExePath + m_sExeName);
dlgAbout.m_sBuild = "Pro-JCL version: " +
dlgAbout.cFileVersion.GetProductVersion();
In the about box, I have a cstatic control that displays the version number.
This approach has been a real convenience in my interactions with the QA group. Hope you find it useful.
Download updated demo project - 61 Kb
MSDN recently provided a mechanism for incrementing the version number after each build. The key thing was that they slipped the version resource into the .rc2 file instead of the .rc file. I modified my addin to do the the same. i.e., follow their instructions for moving and modifying the version resource from the .rc to the .rc2 file. Then, add the add-in to your ide as before.
The file AutoBuild.h will be generated by the developer studio add-in and will contain the following:
#ifndef __AUTOBUILD_H__
#define __AUTOBUILD_H__
#define INCREMENT_VERSION FALSE
#define FILEVER 1,0,0,1
#define PRODUCTVER 1,0,0,1
#define STRFILEVER "1, 0, 0, 1\0"
#define STRPRODUCTVER "1, 0, 0, 1\0"
#endif
Include the generated file in your project and set the INCREMENT_VERSION
flag to TRUE
if you want to increment the version number with each build. The version will be incremented with each build. i.e., 1,0,0,1 will become 1,0,0,2 ... 1,0,0,3 ...
By using FILEVER
, PRODUCTVER
, STRFILEVER
, STRPRODUCTVER
strings in place of the version numbers inside the version resource as the MSDN article demonstrates, we get rid of the irritating warning message from developer studio that its reloading the modified .rc file. That message motivated me to modify the code to use their approach.
Given below is the MSDN / VCDJ documentation for moving the version resource from the .rc file to the .rc2 file and making the appropriate changes to the version number strings.
Remove the version resource from the .rc file and place it in the .rc2 file:
Open both MyProject.rc and MyProject.rc2 (found in the Res folder), in a text editor. To use the Visual C++ editor, click Open on the File menu and select Text in the Open As list for the MyProject.rc file.
Find the version resource statements in MyProject.rc. It should look something like:
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "Sample Application\0"
VALUE "CompanyName", "Microsoft Corp.\0"
VALUE "FileDescription", "MyProject MFC Application\0"
VALUE "FileVersion", "1, 0, 0, 1\0"
VALUE "InternalName", "MyProject\0"
VALUE "LegalCopyright", "Copyright (C) 1999\0"
VALUE "OriginalFilename", "MyProject.EXE\0"
VALUE "ProductName", "MyProject Application\0"
VALUE "ProductVersion", "1, 0, 0, 1\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
Cut the version resource from the MyProject.rc file and paste it into the MyProject.rc2 file below the comment "Add manually edited resources here." For information about what each one of the fields in the resource means, see the VERSIONINFO
resource statement in Help.
Replace the FILEVERSION
and PRODUCTVERSION
data with macros FILEVER
and PRODUCTVER
. Similarly, replace the FileVersion
and ProductVersion
string data with the macros STRFILEVER
and STRPRODUCTVER
.
Add a #include AutoBuild.h
immediately before the VS_VERSION_INFO
resource statement. Now the version resource will look like:
#include "AutoBuild.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION FILEVER
PRODUCTVERSION PRODUCTVER
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "Sample Application\0"
VALUE "CompanyName", "Microsoft Corp.\0"
VALUE "FileDescription", "MyProject MFC Application\0"
VALUE "FileVersion", STRFILEVER
VALUE "InternalName", "MyProject\0"
VALUE "LegalCopyright", "Copyright (C) 1997\0"
VALUE "OriginalFilename", "MyProject.EXE\0"
VALUE "ProductName", "MyProject Application\0"
VALUE "ProductVersion", STRPRODUCTVER
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
The file AutoBuild.h will be generated by the developer studio add-in and will contain the following:
#ifndef __AUTOBUILD_H__
#define __AUTOBUILD_H__
#define INCREMENT_VERSION FALSE
#define FILEVER 1,0,0,1
#define PRODUCTVER 1,0,0,1
#define STRFILEVER "1, 0, 0, 1\0"
#define STRPRODUCTVER "1, 0, 0, 1\0"
#endif