0

I am using VS2019. I one solution I have few c++ projects sharing a common static library. For managing version info I use Version resource. The only modification on executables I do perform is changing the library's code. So I would like for the exec's version to be determined by the version of my lib.

I was thinking about whether it is possible to dynamically change the version of my executables based on a version of lib, er external resource. For example as a precompile event?

I want to controll only FILEVERSION property.

1 Answers1

1

One solution would be to factor out the library's version into one of its headers, and include that.

include/MyLib/Version.rh:

#pragma once

#define MYLIB_VERSION_STR()   "1.0.0"
#define MYLIB_VERSION_COMMA() 1, 0, 0, 0

Then you can #include it into the library's RC file, as well as your project's, and use it within the VERSION resource:

#include <MyLib/Version.rh>

VS_VERSION_INFO VERSIONINFO
 FILEVERSION MYLIB_VERSION_COMMA()
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904B0"
        BEGIN
            VALUE "FileVersion", MYLIB_VERSION_STR()
        END
    END
END
Quentin
  • 62,093
  • 7
  • 131
  • 191
  • I tried a solution like this, but If a create a resource or modify something on save it overwrites my VERSION_INFO with one with solved define – Perry May 09 '23 at 14:19
  • @Perry IIRC this is a "feature" of Visual Studio. Their solution is to put your manually edited code in a `.rc2` file that you include from the generated `.rc`. – Quentin May 09 '23 at 14:22