如何在两个 Visual C++ 项目之间共享相同的产品版本? [英] How can I share same Product Version between two Visual C++ projects?

查看:26
本文介绍了如何在两个 Visual C++ 项目之间共享相同的产品版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个 Visual C++ 项目,它们都有一个 RC 文件,其中定义了现场产品版本.我怎样才能让这两个项目从全球范围内获得这个版本?全局RC文件或者有什么解决方案?

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?

推荐答案

最适合我的是添加两个解决方案项".一个是 #defines 一些版本字符串的 .h 文件,另一个是包含 .h 和 BLOCK "StringFileInfo" 的 .rc 文件,它使用定义.

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.

每个项目的单独资源文件使用一个 TEXTINCLUDE 引入解决方案的 .rc 内容.

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) 两个解决方案项添加如下:

1) The two solution items are added as so:

2) version.h 有一些 #defines 将在 VersionInfo.rc2 中使用

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 使用定义

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.

您可能想设置的另一个字段是FileDescription",但这通常是基于每个项目的.请记住,这可以包含您希望在项目之间共享的任何内容.

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) 在每个进程中包含 VersionInfo.rc2.这是通过在 Resource View 中右键单击每个项目的 .rc 并选择 Resource Includes 来完成的.

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.

添加到编译时指令:#include "../VersionInfo.rc2"

这可以通过将以下内容添加到项目的 .rc 文件中手动完成,但最好让 Visual Studio 管理它可以为您管理的所有内容.

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.

这篇关于如何在两个 Visual C++ 项目之间共享相同的产品版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆