Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29070 Discussions

How to add version information to a Intel Fortran EXE in Visual Studio

Bryan_H_1
New Contributor I
2,642 Views

I would like to add version information to a Fortran EXE when it is built.  I would like the version number to follow the notes below.  What is the recommended approach for doing this?

 

Major = pulled from file

Minor = pulled from file

Release = number of days since Jan 1 2000

Build = number of seconds since midnight (00:00:00), divided by 2

0 Kudos
1 Solution
Bryan_H_1
New Contributor I
828 Views
SUMMARY:
========
With @Steve_Lionel 's and @andrew_4619 's guidance I was able to add version information to a Fortran EXE in my desired format.  To do this I needed to:
 
1/ Fix registry issue that broke the Visual Studio/Intel Fortran's ability to compile resources.
2/ Add a resource file.  Add version resource item into resource file.
3/ Create a script file to update the version data in the resource file.
4/ Add a pre-build event to invoke the script file.
 
Bryan_H_1_0-1746806565719.png

 

Bryan_H_1_1-1746806654457.png

 

 
DETAILS:
========
 
1/ Fix Broken Resource Compiler
--------------------------------------------------
I struggled to get the resource compiler to work as expected due to 3rd party software breaking it (Embarcadero RAD Studio 11.3).  After many failed attempts to fix this, @Steve_Lionel had the brilliant suggestion to purge the .RC data in the registry.
 

Registry change:

        Initial Value
                HKEY_CLASSES_ROOT\.rc.
                        (Default) , REG_SZ, BDS.rc

        Change value "BDS.rc" to ""
                HKEY_CLASSES_ROOT\.rc.
                         (Default) , REG_SZ,

 
2/ Add a resource file
------------------------
In the Visual Studio Solution Explorer
Add > New Item > Resource File (.rc) ... name it as you wish.  I kept the default "Resource1.rc" ... click Add
    Note 1: Just the presence of the .rc file should be enough to invoke the resource compiler
    Note 2: I had path issues that required me to add the absolute path for each #include <file> in each file directly or indirectly referenced in the "Resource1.rc" that could not be resolved.
 
In the Visual Studio Solution Explorer
Double-Click the resource file "Resource1.rc" to open it in a visual resource editor
In the visual editor, right-click "Resource1.rc" > Select "Add Resource"
In the "Add Resource" dialog, select "Version", click the "New" button
 
3/ Create a script file
-------------------------
While a batch file or powershell file should work, I created a C# script file and added it to the project.  See PreBuildScript.csx in attached zip for details.
    Note 1: This requires Visual Studio to have the ability to create dotnet applications.  If missing this can be added thru the Visual Studio installer, modify button, and selecting the "DotNet desktop development" workflow.
    Note 2: To invoke the script the dotnet-script processor needs to be installed.  To install this, at a command prompt run:
    dotnet tool install -g dotnet-script
 
4/ Add Pre-Build Event
------------------------
In the Visual Studio Solution Explorer, right-click the project > Properties
In the "Property Pages" dialog, select "Build Events" > "Pre-Build Event"
In the "Command Line" edit box, add:
dotnet-script .\PreBuildScript.csx
 
 
Now on each compile the Pre-Build event updates the version information in the resource file, then the resource compiler compiles the updated resource file, then the compiled resource is linked into the generated EXE.

 

View solution in original post

39 Replies
andrew_4619
Honored Contributor III
816 Views

In VS if I do Help>About is see:

 

Microsoft Visual Studio Community 2022
Version 17.0.5
VisualStudio.17.Release/17.0.5+32112.339
Microsoft .NET Framework
Version 4.8.09032

Installed Version: Community

Visual C++ 2022 00482-90000-00000-AA095
Microsoft Visual C++ 2022

ASP.NET and Web Tools 2019 17.0.795.42246
ASP.NET and Web Tools 2019

C# Tools 4.0.1-1.21568.1+6ab6601178d9fba8c680b56934cd1742e0816bff
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Intel® C++ Compiler 2025.1
Intel® C++ Compiler 2025.1, Copyright © 2002-2025 Intel Corporation. All rights reserved.

Intel® C++ Compiler Classic 2021.10
Intel® C++ Compiler Classic 2021.10, Copyright © 2002-2023 Intel Corporation. All rights reserved.

Intel® DPC++ Compatibility Tool 2025.1
Intel® DPC++ Compatibility Tool 2025.1, Copyright © 2019-2025 Intel Corporation. All rights reserved.

Intel® Fortran Compiler 2025.1
Intel® Fortran Compiler 2025.1, Copyright © 2002-2025 Intel Corporation. All rights reserved.

Intel® Inspector 2024 1.3.21
Intel® Inspector 2024, (Plugin Version 1.3.21), Copyright © 2009-2023 Intel Corporation. All rights reserved.

Intel® oneAPI DPC++ Compiler 2025.1
Intel® oneAPI DPC++ Compiler 2025.1, Copyright © 2019-2025 Intel Corporation. All rights reserved.

Intel® oneAPI Menu & Samples 10.10.392.9731
Intel® oneAPI Visual Studio Menu & Samples Extension

Intel® Performance Libraries 2025.1
Intel® Performance Libraries 2025.1, Copyright © 2019-2025 Intel Corporation. All rights reserved.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package

NuGet Package Manager 6.0.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Test Adapter for Boost.Test 1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0
Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

TypeScript Tools 17.0.1001.2002
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.0.1-1.21568.1+6ab6601178d9fba8c680b56934cd1742e0816bff
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.

Visual Studio Tools for CMake 1.0
Visual Studio Tools for CMake

0 Kudos
Bryan_H_1
New Contributor I
809 Views

No sure what difference to focus on.  The items that look interesting to me, are the items below that you have that but I don't:

  • Intel C++ Compiler Classic 2021
  • Microsoft Visual Studio VC Package
  • Visual Studio Tools for CMake.

 

Below is the whole comparison:

Bryan_H_1_0-1746056015204.png

Bryan_H_1_1-1746056015206.png

Bryan_H_1_2-1746056015207.png

 

 

 

 

 

0 Kudos
andrew_4619
Honored Contributor III
807 Views

The VC package is the one you need.

Bryan_H_1
New Contributor I
711 Views

SUMMARY:

==========

1/ Do you know how I can get the VC package installed?

2/ I found that I can add version information to a Visual Studio C++ project, just not for an Intel Fortran project.  Why might this be?

 

DETAILS:

========

I tried a few tests to get VC package installed:

Visual Studio installer ... Repair ... issues persisted

Visual Studio installer ... installed every option under Desktop development with C++ ... issues persisted

Uninstalled Intel-OneAPI.  Uninstalled Visual Studio.  Installed Visual Studio (17.8.34622.214) with default Desktop development with C++.  Installed Intel-OneAPI (intel-oneapi-hpc-toolkit-2025.1.0.665_offline.exe) with every option ... issues persisted.  Now also getting "The 'IntelGfxDbgPackage' package did not load correctly." at Visual Studio startup.

 

I tested Creating a C++ application:

Created a c++ console project.

Right-clicked on Resource files in solution explorer > Add > Resource.  This added the resource with no error messages.

Double-clicked on Resource in Solution Explorer.  This opened Resource View.

Right-clicked on Resource.rc in Resource View > Add Resource ... > Version.

Clean & Build.

Right-Clicked on the EXE created selected properties.

In the property dialog it shows the expected version information (File version 1.0.0.1, Product name  TODO: <Product Name>, etc.)

 

 

 

0 Kudos
Steve_Lionel
Honored Contributor III
754 Views

He has Visual C++ - without that, nothing would work. 

Let me see if I can attach the project ZIP again. Hey, it works this time. Try building this.

If you open a directory window for the folder where you have the .rc file, what does it display as Type? It should be "Resource Script". I notice in your screenshot of the project that the icon for the .rc file isn't what I'd expect - it should look like this:

Steve_Lionel_1-1746129861220.png

 

If you right click on the .rc, is Compile one of the options? If not, I recommend doing a "Repair" of Visual Studio from the installed Apps menu in Windows Settings.

0 Kudos
Bryan_H_1
New Contributor I
745 Views

SUMMARY:

==========

It seems like files with the .rc extension are associated with a different application.  However, running a visual studio repair did not change the file association.

 

DETAILS:

=============================

When I try to open the project Console1 that you sent, I get a series of messages like the one below:

Bryan_H_1_0-1746131706099.png

Then I get the following:

Bryan_H_1_1-1746131843431.png

=================

When I right-click the resource from the solution explorer I do not get a compile option:

Bryan_H_1_2-1746132013274.png

==============================================

 In Windows Explorer it shows Resource1.rc as a "Resource File" and not a "Resource Script".  It looks like it associates *.rc files with a different application.

Bryan_H_1_3-1746132313411.png

 

 

 

 

0 Kudos
Bryan_H_1
New Contributor I
711 Views

Summary
========
It seems that RC file compiling in Visual Studio is broken after RAD Studio is installed.

After the compiling of RC files is broken from this, I have not found a way to make it work again.

 

Question

========

Any suggestions on things to try to recover RC file compilation in Visual Studio?

 

Details
========

Tested on a 3rd PC that has never had RAD Studio installed on it:
------------------------------------------------------------------
- Windows Explorer shows .rc files as "Resource Script"
- Visual Studio cannot open .rc file. It shows "fatal error RC1015: cannot open include file 'winres.h'.
- Right-click on Resource1.rc in Visual Studio Solution Explorer gives a compile option. Selecting it shows it was compiled.
- Clean, Build in Visual Studio reports "Compiling Resources...". Checking the generated EXE shows version information.
- In Windows 10 "Settings | Choose default apps by file type", it shows "Microsoft Visual Studio 2022" as the default all.

Tested impact of RAD Studio:
-----------------------------
- Right-click on Resource1.rc in Visual Studio Solution Explorer. It gives a compile option. Selecting it seems to work.
- Installed RAD Studio 11.3. (It ran an installer for Windows SDK)
- Reboot
- Right-click on Resource1.rc in Visual Studio Solution Explorer. It does not give a compile option.

 

Tested recovery from RAD Studio:
---------------------------------
- Ran Visual Studio Installer repair.
- Right-click on Resource1.rc in Visual Studio Solution Explorer. It does not give a compile option.
- Uninstalled RAD Studio 11.3.
- Right-click on Resource1.rc in Visual Studio Solution Explorer. It does not give a compile option.
- ReRan Visual Studio Installer repair.
- Right-click on Resource1.rc in Visual Studio Solution Explorer. It does not give a compile option.
- Hacked registry to try to reset .RC file associations
- In RegEdit went to Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.rc
- renamed .rc to .rc_old
- Right-click on Resource1.rc in Visual Studio Solution Explorer. It does not give a compile option.
- Ran Visual Studio Installer repair.
- Right-click on Resource1.rc in Visual Studio Solution Explorer. It does not give a compile option.
- Uninstalled Windows Software Development Kit for Windows 8.1
- Uninstalled Windows Software Development Kit - Windows 10.15063.137
- Uninstalled Windows Software Development Kit - Windows 10.19041.685
- Uninstalled Windows Software Development Kit - Windows 10.22621.3323
- Uninstalled Windows SDK AddOn
- Reboot
- Right-click on Resource1.rc in Visual Studio Solution Explorer. It does not give a compile option.
- Ran Visual Studio Installer repair.
- Right-click on Resource1.rc in Visual Studio Solution Explorer. It does not give a compile option.
- Run Visual Studio Installer. Add Windows SDK for Windows 11.
- Right-click on Resource1.rc in Visual Studio Solution Explorer. It does not give a compile option.
- Ran Intel HPC Toolkit, v.2024 repair
- Right-click on Resource1.rc in Visual Studio Solution Explorer. It does not give a compile option.

0 Kudos
Steve_Lionel
Honored Contributor III
699 Views

OK. At this point, uninstall Intel HPC Toolkit and Visual Studio.  Reinstall Visual Studio (see Installing Microsoft Visual Studio* for Use with Intel® Compilers) and then the Intel HPC Toolkit. I have seen other complaints that some other product changed the association of rc files to create this symptom.

Now, winres.h ought to be found - if it still isn't, let us know.

0 Kudos
andrew_4619
Honored Contributor III
673 Views
0 Kudos
JohnNichols
Valued Contributor III
641 Views

RC1015 error is interesting, see above, it says on the page about RC1015 that one has to hard code in the things like winres.h with a full path at the original, it will not work as an include directory on the property page. Fileseek finds then in a jiffy. 

I spent 30 minutes and then the error disappears and the RC page looks like normal.  I tried the include path as a start and it did not work.  

// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1999 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

// winres.h - Windows resource definitions
//  extracted from WINUSER.H and COMMCTRL.H

#ifdef _AFX_MINREBUILD
#pragma component(minrebuild, off)
#endif

#define VS_VERSION_INFO     1

#ifdef APSTUDIO_INVOKED
#define APSTUDIO_HIDDEN_SYMBOLS // Ignore following symbols
#endif

#ifndef WINVER
#define WINVER 0x0400   // default to Windows Version 4.0
#endif

#include <C:\Program Files\Microsoft Visual Studio\2022\Preview\SDK\ScopeCppSDK\vc15\SDK\include\um\winresrc.h>

#ifdef _MAC
#define DS_WINDOWSUI    0x8000L
#endif

// operation messages sent to DLGINIT
#define LB_ADDSTRING    (WM_USER+1)
#define CB_ADDSTRING    (WM_USER+3)

#ifdef APSTUDIO_INVOKED
#undef APSTUDIO_HIDDEN_SYMBOLS
#endif

#ifdef IDC_STATIC
#undef IDC_STATIC
#endif
#define IDC_STATIC      (-1)

#ifdef _AFX_MINREBUILD
#pragma component(minrebuild, on)
#endif

 As you work through the set each one slowly disappears as an error, but you only get one error at time. If you do not fix these it still compiles but the rc window is text not the nice form.   Final rc window not text now. 

 

Screenshot 2025-05-03 182316.png

This is latest PReview and IFX. 

0 Kudos
Bryan_H_1
New Contributor I
575 Views

SUMMARY:
=========
Uninstalling HPC ToolKit and Visual Studio, then reinstalling did not fix the issue. I still get "fatal error RC1015: cannot open include file 'winres.h'" when opening resources files in visual studio.  Compiling the Fortran console app does not invoke the resource compiler.  The app does not have version information added to it.

 


DETAILS:
==========

 

Test 1
---------------------------------------------------------------------------------
Uninstalled RAD Studio 11.3

Uninstalled HPC ToolKit

Note 1: Intel Parallel Studio XE 2017 update 4 Composer Edition still installed

Note 2: Intel Parallel Studio XE 2019 Update 5 still installed

Note 3: Intel Visual Fortran Restributables on IA-32 still installed

Note 4: Intel Software Manager still installed

Note 5: Intel openAPI Base Toolkit still installed

Uninstall visual Studio

Rebooted

Reviewed "Installing Microsoft Visual Studio for Use with Intel Compilers"

Note 1: Only certain combinations of Intel Fortran and Visual Studio have been tested together. Specificially, 2025.1 Intel Compiler has been validated with Visual Studio VS 2022 17.12.4

Note 2: it is necessary to install the Desktop development with C++ component from Visual Studio

Install visual studio 17.12

Note 1: Selected only the "Desktop development with C++" workload, and kept its defaults.

Install HPC toolkit 2025.1.1.38

Note 1: In "Prerequisites Check" step it gives a warning that: "Intel C++ Compiler 19.0 Integration(s) in Microsoft Visual Studio is already installed" and "Intel Visual Fortran Compiler 19.0 integration(s) in Microsoft Visual Studio is already installed"

Note 2: In "Integrate IDE" step it defaults to Microsoft Visual Studio 2022. It shows Microsoft Visual Studio 2019 but it is disabled and unchecked/uncheckable.

Rebooted

Open Visual Studio | Project Console1 | Double click on Resource1.rc | It still gives: "fatal error RC1015: cannot open include file 'winres.h'

 


Test2
---------------------------------------------------------------------------------
Uninstalled HPC ToolKit

Uninstalled Intel openAPI Base Toolkit

Uninstalled Intel Visual Fortran Restributables

Uninstalled Intel Software Manager

Uninstall FAILED: Intel Parallel Studio XE 2017 update 4 Composer Edition

Note 1: "Windows cannot find c:\programdata\intel\installer\ParallelStudio\cache\...install.exe"

Uninstall FAILED: Intel Parallel Studio XE 2019 Update 5

Note 1: Something seemed to run, but no observable action was taken, and Intel Parallel Studio XE 2019 Update 5 still persists in the list of installed apps.

Uninstalled Visual Studio

rebooted

Installed Visual Studio 17.12

Note 1: Selected only the "Desktop development with C++" workload, and kept its defaults.

Installed HPC toolkit 2025.1.1.38

Note 1: In "Prerequisites Check" step it still gives a warning that: "Intel C++ Compiler 19.0 Integration(s) in Microsoft Visual Studio is already installed" and "Intel Visual Fortran Compiler 19.0 integration(s) in Microsoft Visual Studio is already installed"

Note 2: In "Integrate IDE" step it defaults to Microsoft Visual Studio 2022. It shows Microsoft Visual Studio 2019 but it is disabled and unchecked/uncheckable.

Rebooted

Open Visual Studio | Project Console1 | Double click on Resource1.rc | It still gives: "fatal error RC1015: cannot open include file 'winres.h'

In Visual Studio | Solution Explorer | Clean | Build. 

Note 1: The resource compiler was not mentioned in the build output

Note 2: The application does not have version information in Windows Explorer | Properties | Details.

 

0 Kudos
JohnNichols
Valued Contributor III
556 Views

 I still get "fatal error RC1015: cannot open include file 'winres.h'"

 

As I showed you in my post, RC1015 has an error, all of the *.h type files have to be hard coded in like this 

#include <C:\Program Files\Microsoft Visual Studio\2022\Preview\SDK\ScopeCppSDK\vc15\SDK\include\um\winresrc.h>

there is no shortcuts, it takes about 30 minutes to find them and fix them one at a time.  

You do not need to reinstall anything, but you have to hard code all these files, even in the c++ installation. 

 

0 Kudos
andrew_4619
Honored Contributor III
518 Views

I have never needed to add paths in the .rc file in many years of using.....

The fact that this is needed means something is broken IMO

0 Kudos
JohnNichols
Valued Contributor III
505 Views

Resource Compiler Fatal Error RC1015

  • Article
  • 08/02/2021
  • 6 contributors
Feedback

cannot open include file 'filename'

The given include file does not exist, could not be opened, or was not found.

Make sure that the environment settings are valid and that the correct path for the file is specified. Ensure that sufficient file handles are available to the Resource Compiler. If the file is on a network drive, make sure that you have permissions to open the file.

RC1015 can occur even if the include file exists in a directory specified as an Additional Include Directory in the Configuration Properties -> Resources -> General property page; specify the complete path to the include file.

 

Andrew:  This is the weirdest statement ever, but it proved correct, the program will run and work if you do not do this but it gives you the errors, you can just ignore them and get a nasty looking RC file or spend 30 minutes doing complete paths in all the Microsoft files in VS and C++ and there are a lot and one gets a standard RC file in VS.  

As a curious Meatball Engineer, I just did it and it worked, I report the world as it is, not as we want it to be.  No one has touched this since 08/02/2021 so I think we are stuck with a low priority error.  The fix is annoying but not fatal. 

 

include file exists in a directory specified as an Additional Include Directory

++ I did this first it does not work. 

0 Kudos
Bryan_H_1
New Contributor I
469 Views

Thanks for your feedback, and I appreciate your efforts. 

I hand edited the paths to be absolute like you suggested.  This does allow the RC file to now open and be in a visual non-text editor.  However, this does not restore the "Compile" right-click option in the Solution Explorer.  When the program is compiled, it does not invoke the resource compiler.  The resulting EXE does not contain version information.

 

Bryan_H_1_0-1746580781434.png

 

0 Kudos
Steve_Lionel
Honored Contributor III
429 Views

Uninstall The Intel oneAPI and Visual Studio. Delete the registry entry for HKEY_CLASSES_ROOT\.rc . Reinstall.

Bryan_H_1
New Contributor I
372 Views

Thanks Steve, that worked!!  I think it might have even solved the path issues, but I will need to retest.

 

SUMMARY
=========
The inability to compile resources into a Fortran program seems to be caused by a registry setting. Clearing the setting fixed the issues I was experiencing.

Registry change:

        Initial Value
                HKEY_CLASSES_ROOT\.rc.
                        (Default) , REG_SZ, BDS.rc

        Change value "BDS.rc" to ""
                HKEY_CLASSES_ROOT\.rc.
                         (Default) , REG_SZ,

 


DETAILS
=========

Test 1 - Full Uninstall / Registry Delete / Reinstall on PC 3
-------------------------------------------------------------------
Uninstall Intel oneAPI
Uninstall Visual Studio
Delete registry Key for HKEY_CLASSES_ROOT\.rc.

        Note: The below is the content of the registry key and its sub-keys:
                HKEY_CLASSES_ROOT\.rc.
                        (Default) , REG_SZ, BDS.rc
                        Content Type , REG_SZ, text/plain
                        PerceivedType, REG_SZ, text

                HKEY_CLASSES_ROOT\.rc.\OpenWithProgids
                        (Default), REG_SZ, (value not set)

                HKEY_CLASSES_ROOT\.rc.\PersistentHandler
                       (Default), REG_SZ, (5e941d80-bf96-11cd-b579-08002b30bfeb)

Reboot

Install Visual Studio 17.12.7
        Selected Desktop Development with C++

Install Intel oneAPI
Retest.
        Opened Steve's Console1 solution in Visual Studio.
        In Solution Explorer I am able to open RC file with no path warnings
        In Solution Explorer I have the "Compile Resource" option. Selecting it compiles the resource successfully
        When I Clean | Build, it invokes the Resource Compiler.
        When I inspect the EXE it has version information.


Test 2 - Registry Edit on PC2
----------------------------------
Change registry

        Initial Value
              HKEY_CLASSES_ROOT\.rc.
                    (Default) , REG_SZ, BDS.rc

        Change value "BDS.rc" to ""
              HKEY_CLASSES_ROOT\.rc.
                    (Default) , REG_SZ,

 

Retest.
        Opened Steve's Console1 solution in Visual Studio.
        In Solution Explorer I am able to open RC file with no path warnings
        In Solution Explorer I have the "Compile Resource" option. Selecting it compiles the resource successfully
        When I Clean | Build, it invokes the Resource Compiler.
        When I inspect the EXE it has version information.

andrew_4619
Honored Contributor III
338 Views
Hurrah! Glad to see you got there. It was clear to me the the instal was broken in some way but when registry has been messed up by a third app that can be difficult to find and fix.
0 Kudos
Bryan_H_1
New Contributor I
829 Views
SUMMARY:
========
With @Steve_Lionel 's and @andrew_4619 's guidance I was able to add version information to a Fortran EXE in my desired format.  To do this I needed to:
 
1/ Fix registry issue that broke the Visual Studio/Intel Fortran's ability to compile resources.
2/ Add a resource file.  Add version resource item into resource file.
3/ Create a script file to update the version data in the resource file.
4/ Add a pre-build event to invoke the script file.
 
Bryan_H_1_0-1746806565719.png

 

Bryan_H_1_1-1746806654457.png

 

 
DETAILS:
========
 
1/ Fix Broken Resource Compiler
--------------------------------------------------
I struggled to get the resource compiler to work as expected due to 3rd party software breaking it (Embarcadero RAD Studio 11.3).  After many failed attempts to fix this, @Steve_Lionel had the brilliant suggestion to purge the .RC data in the registry.
 

Registry change:

        Initial Value
                HKEY_CLASSES_ROOT\.rc.
                        (Default) , REG_SZ, BDS.rc

        Change value "BDS.rc" to ""
                HKEY_CLASSES_ROOT\.rc.
                         (Default) , REG_SZ,

 
2/ Add a resource file
------------------------
In the Visual Studio Solution Explorer
Add > New Item > Resource File (.rc) ... name it as you wish.  I kept the default "Resource1.rc" ... click Add
    Note 1: Just the presence of the .rc file should be enough to invoke the resource compiler
    Note 2: I had path issues that required me to add the absolute path for each #include <file> in each file directly or indirectly referenced in the "Resource1.rc" that could not be resolved.
 
In the Visual Studio Solution Explorer
Double-Click the resource file "Resource1.rc" to open it in a visual resource editor
In the visual editor, right-click "Resource1.rc" > Select "Add Resource"
In the "Add Resource" dialog, select "Version", click the "New" button
 
3/ Create a script file
-------------------------
While a batch file or powershell file should work, I created a C# script file and added it to the project.  See PreBuildScript.csx in attached zip for details.
    Note 1: This requires Visual Studio to have the ability to create dotnet applications.  If missing this can be added thru the Visual Studio installer, modify button, and selecting the "DotNet desktop development" workflow.
    Note 2: To invoke the script the dotnet-script processor needs to be installed.  To install this, at a command prompt run:
    dotnet tool install -g dotnet-script
 
4/ Add Pre-Build Event
------------------------
In the Visual Studio Solution Explorer, right-click the project > Properties
In the "Property Pages" dialog, select "Build Events" > "Pre-Build Event"
In the "Command Line" edit box, add:
dotnet-script .\PreBuildScript.csx
 
 
Now on each compile the Pre-Build event updates the version information in the resource file, then the resource compiler compiles the updated resource file, then the compiled resource is linked into the generated EXE.

 

Reply