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).
#define PRODUCT_VERSION 184.108.40.206
#define PRODUCT_VERSION_STR "220.127.116.11"
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 18.104.22.168.
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.
// Neutral resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
VALUE "CompanyName", "TODO: "
VALUE "FileDescription", "TODO: "
VALUE "FileVersion", PRODUCT_VERSION_STR
VALUE "InternalName", "testResources.exe"
VALUE "LegalCopyright", "TODO: (c) . All rights reserved."
VALUE "OriginalFilename", "your_project.exe"
VALUE "ProductName", "TODO: "
VALUE "ProductVersion", PRODUCT_VERSION_STR
VALUE "Translation", 0x409, 1252
#endif // Neutral resources
- 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“:
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"LANGUAGE 9, 1\r\n"
"#include ""res\\your_project.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
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 22.214.171.124) and in ProductVersion we have the current build version (126.96.36.199).
Demo application - AutoProductVersion (2147 downloads)