Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I share same Product Version between two Visual C++ projects?

I have 2 Visual C++ projects which both have an RC file where the Field Product Version is defined. How can I make both projects to get this version from a global place? Global RC file or what solutions are there?

like image 664
dbrasco Avatar asked Nov 28 '12 14:11

dbrasco


1 Answers

What works well for me is adding two "Solution Items". One is a .h file that #defines some version strings, and another is the .rc file that has an include to the .h and BLOCK "StringFileInfo" that uses the defines.

Individual resource files for each project use a TEXTINCLUDE to bring in the contents of the solution's .rc.

That is a lot to take in. Let me show you what I mean...

1) The two solution items are added as so:

Solution Items

2) version.h has some #defines that will be used in VersionInfo.rc2

#define SOLUTIONFILEVERSION 1,00,0000,00000
#define SOLUTIONFILEVERSIONSTRING "1,00,0000,00000"
#define COPYRIGHT "Copyright 2012"
#define PRODUCTNAME "Your product name"
#define COMPANYNAME "Your company name"

3) VersionInfo.rc2 uses the defines

#include "version.h"
VS_VERSION_INFO VERSIONINFO
 FILEVERSION SOLUTIONFILEVERSION
 PRODUCTVERSION SOLUTIONFILEVERSION
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "CompanyName", COMPANYNAME
            VALUE "FileVersion", SOLUTIONFILEVERSIONSTRING
            VALUE "LegalCopyright", COPYRIGHT
            VALUE "ProductName", PRODUCTNAME
            VALUE "ProductVersion", SOLUTIONFILEVERSIONSTRING
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END

You will want a new line at the end of this file to make the resource compiler happy when it is included in the next step.

Another field you might like to set is "FileDescription" but that is typically on a per-project basis. Remember, this can contain anything you would like to be shared between your projects.

4) Include the VersionInfo.rc2 in each process. This is done by right clicking on the each project's .rc in the Resource View and selecting Resource Includes.

Add to the Compile-time directives: #include "../VersionInfo.rc2"

Compile-time directives

This could be done manually by adding the following to the project's .rc file but it is probably better to let Visual Studio manage everything it can for you.

3 TEXTINCLUDE 
BEGIN
    "#include ""../VersionInfo.rc2""\r\n"
    "\0"
END

/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#include "../VersionInfo.rc2"
/////////////////////////////////////////////////////////////////////////////

Phew....that was a mouthful. But now you should be able to change your product versions from one spot.

like image 79
Sean Cline Avatar answered Oct 19 '22 11:10

Sean Cline