0

Trying to automate some of our processes in a C++ Windows app build using Jenkins. What we would like to do is make the updating of the version information in the resource file (.rc) automatic. Currently there is a script that prompts user for which version that they want to release, and preps everything for automated building, i.e. creates branch etc.

We would like part of the process to update the .rc file. Are there tools to edit .rc files programatically that can be run from the command line?

bpeikes
  • 3,495
  • 9
  • 42
  • 80
  • 2
    Not sure if it helps, but you can replace the values in your `VERSIONINFO` fields (in the .rc file) with macros (defined in a .h file that's included by that .rc). So, instead of `PRODUCTVERSION "1.2.3.4"` you could have `PRODUCTVERSION MyVersion` and `#define MyVersion "1.2.3.4"` in the header. That makes the task a bit simpler, maybe - just modifying (or writing) a `.h` file. – Adrian Mole Mar 23 '21 at 15:38
  • Can you do the same for FileVersion and ProductVersion strings? – bpeikes Mar 24 '21 at 02:46

1 Answers1

0

First of all, you should put the code below in a .rc2 file that is neither interpreted nor modified by Visual Studio and include that file in your .rc file.

In order to yield the version strings, you need two helper functions that concatenate the stringified numbers into a string.

The variables F1 through F4 can be defined by including a header file. Ideally you would create a header from the user input that defines just those four variables. This keeps the whole rest of your code base unchanged. The method is identical for the product verion.

#define F1 1  // Defined by an included header
#define F2 2
#define F3 3
#define F4 4

// MyAppVersionInfo.rc2
#define STRTMP(V1, V2, V3, V4) #V1 "." #V2 "." #V3 "." #V4
#define STR(V1, V2, V3, V4) STRTMP(V1, V2, V3, V4)
#define FVC F1,F2,F3,F4
#define FVS STR(F1,F2,F3,F4)

VS_VERSION_INFO VERSIONINFO
  FILEVERSION    FVC
  ...
    VALUE "FileVersion", FVS

Note that I chose very short identifiers in this example to keep stackoverflow.com happy.

Frank Heimes
  • 100
  • 6
  • Just make sure `#include "MyAppVersioninfo.rc2"` is added to **Compile-time directives** edit box, and not to "Read-only symbol directives". Otherwise VS will automatically add the copy of VS_VERSION_INFO to .rc file, with all macros expanded. – Dialecticus Mar 10 '22 at 12:55