2

I was surprised to discover that apparently it is not possible to import C predefined macros inside the resource files (.rc) because Resource Compiler is not able to deal with them.

I was trying to put the version information inside a version.h that would be generated / updated by the build system. This file was supposed to be included from the resource.rc so when you build the resources you will always get the same versions across all the built files.

It seems that this has something to do with RC_INVOKED and this bug http://connect.microsoft.com/VisualStudio/feedback/details/532929/rc4011-warnings-from-vc10-rc -- which is closed as "as-designed".

How can I solve this problem?

Is the only option to patch the final exe in order to update the version information? ... I would prefer not do to this and use a more standard way for this.

4

1 回答 1

2

资源编译器可以很好地处理包含和预处理器定义。例如,它不能很好地处理包括 Windows.h 的问题。但是我想不出任何充分的理由为什么您需要在资源编译器使用的文件中使用它。只需使用不包含导致警告的任何内容的头文件,然后定义您需要的内容。作为示例,我们在这里使用的典型版本控制可以做到这一点并且效果很好:有一个.rc 文件,它看起来像这样:

#include <winver.h>

#define stringize( x )        stringizei( x )
#define stringizei( x )       #x

#ifdef VRC_INCLUDE
  #include stringize( VRC_INCLUDE )
#endif

#ifdef _WIN32
  LANGUAGE 0x9,0x1
  #pragma code_page( 1252 )
#endif

1 VERSIONINFO
 FILEVERSION    VRC_FILEVERSION
 PRODUCTVERSION VRC_PRODUCTVERSION
 FILEFLAGSMASK  0x1L
 FILEFLAGS      VS_FF_DEBUG
 FILEOS         VOS__WINDOWS32
 FILETYPE       VRC_FILETYPE
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "040904E4"
    BEGIN
      VALUE "CompanyName",      stringize( VRC_COMPANYNAME )
      VALUE "FileDescription",  stringize( VRC_FILEDESCRIPTION )
      VALUE "FileVersion",      stringize( VRC_FILEVERSION )
      VALUE "LegalCopyright",   stringize( VRC_COPYRIGHT )
      VALUE "InternalName",     stringize( VRC_ORIGINALFILENAME )
      VALUE "OriginalFilename", stringize( VRC_ORIGINALFILENAME )
      VALUE "ProductName",      stringize( VRC_PRODUCTNAME )
      VALUE "ProductVersion",   stringize( VRC_PRODUCTVERSION )
    END
  END
  BLOCK "VarFileInfo"
  BEGIN
    VALUE "Translation", 0x409, 1200
  END
END

从这里开始,可能性几乎是无限的。定义VRC_INCLUDE到包含所有定义的包含文件的完整路径VRC_...

rc /d VRC_INCLUDE=$(VersionMainInclude) ... version.rc

或提供所有定义

rc /d VRC_COMPANYNAME=mycompany ... version.rc

或两者的结合。

为了向您展示可能性,这是我目前对所有使用 git 版本的项目所做的:

  • 每个项目都有一个 version.h #defining 只是一个简短的 VRC_FILEDESCRIPTION 和 VRC_FILEVERSION
  • 有一个主版本.h #defining VRC_COMPANYNAME/VRC_COPYRIGHT/...
  • 该项目包含一个 .targets 文件,该文件在预构建事件中创建一个 version.res
  • msbuild prebuild 事件处理了一些有趣的事情:它创建了一个结合其他两个的新临时头文件,获取简短的 git SHA 和当前数据并将其附加到文件描述字符串,因此它最终看起来像

    Foo Dll [12e454re 30/07/2013]

于 2013-07-30T10:33:26.503 回答