Summary: Having the version details defined in the separately maintained version.inc
via preprocessor macros... How to include the macro values into the resource version definition block?
My version.inc
file is stored in UTF-8 (i.e. pure ASCII in the case). Its full content is the following (the APS_
prefix here is related to the real name of the application, not to the .aps
file generated by the resource compiler):
#define APS_MAJORNUMBER 4
#define APS_MINORNUMBER 5
#define APS_BUILDNUMBER 0
#define APS_MODIFICATIONNUMBER 0
#define APS_BUILDEXT "wx"
#define APS_DATEYEAR 2012
#define APS_DATEMONTH 10
#define APS_DATEDAY 4
The Visual Studio 2012 C++ seems to be more picky about the resource script file (app.rc
) than the Visual Studio 2010 was. The first thing I have noticed is that when editing it manually, I have to keep the UTF-16 encoding. Can you confirm that? Is there any documentation on that?
Say the version block in the app.rc
looks like this:
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
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 0x40004L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040504b0"
BEGIN
VALUE "CompanyName", "TODO: <Company name>"
VALUE "FileDescription", "TODO: <File description>"
VALUE "FileVersion", "1.0.0.1"
VALUE "InternalName", "app.exe"
VALUE "LegalCopyright", "Copyright (C) 2012"
VALUE "OriginalFilename", "app.exe"
VALUE "ProductName", "TODO: <Product name>"
VALUE "ProductVersion", "1.0.0.1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x405, 1200
END
END
In the earlier versions of Visual Studio (2005 and 2010), I was able to have the related version.rc2
like this:
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
#include "version.inc"
#define STR(value) #value
#define STRINGIZE(value) STR(value)
#define APS_FULLVERSION_STR \
STRINGIZE(APS_MAJORNUMBER) "." \
STRINGIZE(APS_MINORNUMBER) "." \
STRINGIZE(APS_BUILDNUMBER) "." \
STRINGIZE(APS_MODIFICATIONNUMBER)
VS_VERSION_INFO VERSIONINFO
FILEVERSION APS_MAJORNUMBER,APS_MINORNUMBER,APS_BUILDNUMBER,APS_MODIFICATIONNUMBER
PRODUCTVERSION APS_MAJORNUMBER,APS_MINORNUMBER,APS_BUILDNUMBER,APS_MODIFICATIONNUMBER
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x29L
#else
FILEFLAGS 0x28L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "Comments", "A fairly useful tool named APS"
VALUE "CompanyName", "The company name"
VALUE "FileDescription", "app"
VALUE "FileVersion", APS_FULLVERSION_STR
VALUE "InternalName", "aps"
VALUE "LegalCopyright", "Copyright © 1993-" STRINGIZE(APS_DATEYEAR)
VALUE "OriginalFilename", "app.exe"
VALUE "PrivateBuild", ""
VALUE "ProductName", "APS of the version 4"
VALUE "ProductVersion", APS_FULLVERSION_STR
VALUE "SpecialBuild", APS_BUILDEXT
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0, 1200
END
END
Then the version.rc2
was included into the app.rc
via editing the app.rc
manually. However, I cannot repeat the process with the Visual Studio 2012 project and resource file. I may be doing some mistake invisible to me. Should that approach work also in Visual Studio 2012?
Thanks for you time and experience,
Petr
Here is the way to do it via Visual Studio 2012 (C++, IDE). Firstly, it seems that all the files (app.rc
, version.rc2
with the version section to be included into app.rc
, and also the version.inc
with the values maintained separately [included into version.rc2
]) must be stored in UTF-16 -- unlike in the earlier versions of Visual Studio. Then I was able to repeat the same approach also in Visual Studio 2012.
However, you do not need to edit the app.rc
file manually. You can use the following steps using the IDE:
- Open the project (
App
) and switch to the Resource View tab. - Unfold the
App
project, unfold itsapp.rc
, and unfold theVersion
folder. You can see theVS_VERSION_INFO
item. - Mark the
VS_VERSION_INFO
item and pres Delete key on the keyboard. The item and its upperVersion
folder disappear. - Mouse right-click the
app.rc
folder, and select the Resource Includes.... The dialog with the same name and with three input panes appear.
- Focus on the bottom pane named Compile-time directives:, and write the
#include "version.rc2"
there. (The file must not have the.rc
extension, but the.rc2
is fine and recommended elsewhere in the MSDN doc.) - Press OK, and save all files (to save also the modified
app.rc
).
The result of the steps is that you will not see the Version
folder and the VS_VERSION_INFO
item in the resource tree (see Resource View tab); however, the above mentioned constructed Version
section (stored inside the version.rc2
) is compiled into the application resources.
Technically, the following parts of the app.rc
file can be found after the steps:
3 TEXTINCLUDE
BEGIN
"#include ""version.rc2""\r\n"
"\0"
END
...
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#include "version.rc2"
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
Any constructive comments to enhance the topic are welcome and will be +1-ed :)
Have a nice time,
Petr
来源:https://stackoverflow.com/questions/12821369/vc-2012-how-to-include-version-info-from-version-inc-maintained-separately