Centralized management of project version
2004-07-29 08:54 atempcode 阅读(1198) 评论(0) 编辑 收藏 举报(for native VC++ projects only)
Nowadays, one solution may contain several exe or dll outputs. A best practice is to mark all the output binary file the same version when release. We all know we can change the version information in the resource editor. But if the solution contains many projects, it is boring and error prongingto change the version information one by one.
So we can centralize the management of the version information using include in the rc file. Suppose XYZ company has a product named ABC to release, the ABC product include several dll outputs.
1. create a basic version information file for all the projects. We use a file from MS VSIP SDK in this step and rename it XYZ.ver.
/***************************************************************************
Copyright (c) Microsoft Corporation, All rights reserved.
This code sample is provided "AS IS" without warranty of any kind,
it is not recommended for use in a production environment.
***************************************************************************/
///////////////////////////////////////////////////////////////////////////
// EnvSdkVersion.ver
//
// Defines the Environment SDK version data
//
///////////////////////////////////////////////////////////////////////////
#ifdef RC_INVOKED
#include <winver.h>
// FILEVERSION VER_FILEVERSION
#ifndef VER_FILEVERSION
#define VER_FILEVERSION 7,0,4,0
#endif
// PRODUCTVERSION VER_PRODUCTVERSION
#ifndef VER_PRODUCTVERSION
#define VER_PRODUCTVERSION VER_FILEVERSION
#endif
// FILEFLAGSMASK VER_FILEFLAGSMASK
#define VER_FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
// FILEFLAGS VER_FILEFLAGS
#ifndef VER_PRIVATEBUILD
#define VER_PRIVATEBUILD 0
#endif
#ifndef VER_PRERELEASE
#define VER_PRERELEASE VS_FF_PRERELEASE
#endif
#ifndef VER_DEBUG
// DEBUG flag is set for debug build, not set for retail build
#if defined(DEBUG) || defined(_DEBUG)
#define VER_DEBUG VS_FF_DEBUG
#else // DEBUG
#define VER_DEBUG 0
#endif // DEBUG
#endif
#define VER_FILEFLAGS (VER_PRIVATEBUILD|VER_PRERELEASE|VER_DEBUG)
// FILEOS VER_FILEOS
#ifndef VER_FILEOS
#define VER_FILEOS VOS__WINDOWS32
#endif
// FILETYPE VER_FILETYPE
#ifndef VER_FILETYPE
#define VER_FILETYPE VFT_DLL
#endif
// FILESUBTYPE VER_FILESUBTYPE
#ifndef VER_FILESUBTYPE
#define VER_FILESUBTYPE VFT2_UNKNOWN
#endif
//-------------------------------------------------------------------------
// StringFileInfo block
// VALUE "CompanyName", VER_COMPANYNAME_STR
#ifndef VER_COMPANYNAME_STR
#define VER_COMPANYNAME_STR "Microsoft Corporation"
#endif
// VALUE "FileDescription", VER_FILEDESCRIPTION_STR EXPORT_TAG
#ifndef VER_FILEDESCRIPTION_STR
#define VER_FILEDESCRIPTION_STR "Microsoft Visual Studio Environment SDK Sample\0"
#endif
// VALUE "FileVersion", VER_FILEVERSION_STR
#ifndef VER_FILEVERSION_STR
#define VER_FILEVERSION_STR "7.01.0001.0\0"
#endif
// VALUE "InternalName", VER_INTERNALNAME_STR
#ifndef VER_INTERNALNAME_STR
#error Define VER_INTERNALNAME_STR ("<Name>.dll\0")
#endif
// VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR
#ifndef VER_LEGALCOPYRIGHT_STR
#define VER_LEGALCOPYRIGHT_STR "Copyright (C) Microsoft Corp. "
#endif
// VALUE "OriginalFilename",VER_ORIGINALFILENAME_STR
#ifndef VER_ORIGINALFILENAME_STR
#define VER_ORIGINALFILENAME_STR VER_INTERNALNAME_STR
#endif
// VALUE "ProductName", VER_PRODUCTNAME_STR
#ifndef VER_PRODUCTNAME_STR
#define VER_PRODUCTNAME_STR "Microsoft Visual Studio Environment SDK"
#endif
// VALUE "ProductVersion", VER_PRODUCTVERSION_STR
#ifndef VER_PRODUCTVERSION_STR
#define VER_PRODUCTVERSION_STR VER_FILEVERSION_STR
#endif
// VALUE "OleSelfRegister", "\0"
#define VER_OLESELFREGISTER
#ifdef VER_LANGUAGENEUTRAL
#define VER_BLOCKHEADER "000004b0"
#define VER_TRANSLATION 0x0
#else
#define VER_BLOCKHEADER "040904B0"
#define VER_TRANSLATION 0x409
#endif
// StringFileInfo block
//-------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
FILEFLAGSMASK VER_FILEFLAGSMASK
FILEFLAGS VER_FILEFLAGS
FILEOS VER_FILEOS
FILETYPE VER_FILETYPE
FILESUBTYPE VER_FILESUBTYPE
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK VER_BLOCKHEADER
BEGIN
VALUE "CompanyName", VER_COMPANYNAME_STR
VALUE "FileDescription", VER_FILEDESCRIPTION_STR
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "InternalName", VER_INTERNALNAME_STR
VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR
VALUE "OriginalFilename",VER_ORIGINALFILENAME_STR
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
#ifdef VER_OLESELFREGISTER
VALUE "OleSelfRegister", "\0"
#endif
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", VER_TRANSLATION, 0x04B0
END
END
#endif // RC_INVOKED
2. Create a version information file of ourselves named abc.ver.
#define VER_FILEVERSION 1,0,1,28
#define VER_COMPANYNAME_STR "XYZ Ltd."
#define VER_FILEDESCRIPTION_STR "ABC\0"
#define VER_FILEVERSION_STR "1.0.1.28\0"
#define VER_LEGALCOPYRIGHT_STR "Copyright (C) 2004 XYZ Ltd. "
#define VER_PRODUCTNAME_STR "XYZ's ABC "
All the dlls will be marked as 1.0.1.28.
3. edit every project's rc file.
remove the VS_VERSION_INFO VERSIONINFO section, and replace with these code:
#define VER_INTERNALNAME_STR "<the dll's name>\0"
#define VER_ORIGINALFILENAME_STR "<the dll's name>\0"
#define VER_LANGUAGENEUTRAL
#include "abc.ver"
#include "xyz.ver"
OK, now every time you need to change the version number of product, you only need to modify one file: the abc.ver.
This trick is very useful in the daily build process, that's the story for another blog entry.