Silviu-Marius Ardelean's blog

a software engineer's web log

Flexible changes for product version properties – Visual C++ binaries

Manually editing of binary files version in the resource editor of Visual Studio IDE is not a viable solution. If we have dozens of projects in our solution, then for each kit building we should need manual resources file edit. Otherwise, we can use a special tool that does this thing for us.
Unfortunately this approach is not the most flexible and could fail.

For our flexible binaries properties changes and in order to avoid manual edit for each rebuild we can create and include a header file (version.h) that contains some constants of product version and file version of our project (.rc files).

We have to include only these constants into this file (version.h):

Then, for each .rc file wherever we have FileVersion and ProductVersion we have to use this constants.
When we will build a new kit, we have to change only these constants and then to start the kit building process. Everything is fine until we add new controls in our projects resource files. Then, because of Visual Studio IDE automation we can get an unlikely surprise: the FileVersion and the ProductVersion properties could be reset to 1.0.0.0.

In order to avoid this issue and edit the version only in a single place I propose the following workaround:

  • Create a version.h header file that have to contain these constants only (as on top). I should recommend to create it into the root solution in order of being easy included in all the projects.
  • Include this file in the project you need to use.
  • Use a text editor (ex. notepad.exe) and include next code section at the end of .rc2 resource file of your project (res\your_project.rc2) – this section contains the include version.h file section, too.
  • Edit “040904e4” block code with same data as if we should edit in a resources editor and use the version.h‘s file defined constants. As you can see in my example, for the FileVersion and ProductVersion properties I use my version.h constants. These properties will not be edited anymore.
  • Delete “// Version” section from default resource file your_project.rc (including comments – recommended).
  • Insert next lines into your_project.rc file after “3 TEXTINCLUDE BEGIN” and before “#define _AFX_NO_SPLITTER_RESOURCES\r\n“:
  • That code block looks like this:

    Don’t forget to edit .rc2 file name with the right file name of your project.

  • In your_project.rc file the section “// Generated from the TEXTINCLUDE 3 resource.” have to contain only next declaration:
  • The rest of the section’s lines have to be deleted.

  • We save both resources files: your_project.rc and your_project.rc2.
  • Rebuild the project and check the new generated binary properties. In the FileVersion we will have the major version (in my case 4.0.0.0) and in ProductVersion we have the current build version (4.3.2.198).
  • Observations
    Once you apply these steps, the product version properties will not possible from the Visual Studio IDE resource editor, anymore (only as edit text file or an external text editor). If we didn’t define something special in our project’s String Table we will see only IDS_ABOUTBOX.

    Demo application - AutoProductVersion (1022)

    Silviu Ardelean

    Software Engineer

    More Posts - Website

    Follow Me:
    TwitterFacebookPinterest

    Share

    One Response to “Flexible changes for product version properties – Visual C++ binaries”

    1. It’s OK with few little remarks:

      1. For FILEVERSION and PRODUCTVERSION, must use comma separator.
      So, in Version.h you have to define

      #define PRODUCT_VERSION 4,3,2,198
      #define PRODUCT_VERSION_STR “4.3.2.198”

      instead of

      #define PRODUCT_VERSION 4.3.2.198
      #define PRODUCT_VERSION_STR “4.3.2.198”

      This is important because usually an application using VerQueryValue gets the language-independent versions (FILEVERSION and PRODUCTVERSION values in the resource script) and not the localized ones (“FileVersion” and “ProductVersion” values).
      Just take a look in “Properties” dialog and note that, if using period and not comma, the shown file version is 4.0.0.0 and not 4.3.2.198 as expected.

      2. It is not obviously necessary an external text editor to manually modify the .rc and .rc2 files. It can be directly performed from Visual Studio IDE: richt-click on file in solution explorer, choose “Open With…” menu item, then “Source Code (Text) Editor”.

      3. This method does not resolve the problem in Setup projects (.vdproj).

    Leave a Reply

    *