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

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

Bryan_H_1
New Contributor I
3,493 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
1,679 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
jimdempseyatthecove
Honored Contributor III
2,304 Views

There are many ways to do this.

One suggestion is to add to the solution a Pre-Build step (that runs a program/batch script), that generates the desired data into an appropriate source file (e.g. a module file).

You may want to add a Post-Build step that copies this file to a LastBuild....) file then deletes the module file.

Jim Dempsey

0 Kudos
Steve_Lionel
Honored Contributor III
2,298 Views

You can add a resource file (.rc) to your build that contains info Windows can display for version info. I have attached a sample file here (generated by Visual Studio), the important block is this:

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 1,0,314,159
 PRODUCTVERSION 1,0,314,159
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x40004L
 FILETYPE 0x0L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "CompanyName", "TODO: <Company name>"
            VALUE "FileDescription", "TODO: <File description>"
            VALUE "FileVersion", "1.0.314.159"
            VALUE "InternalName", "TODO: <Internal name>"
            VALUE "LegalCopyright", "Copyright (C) 2025"
            VALUE "OriginalFilename", "TODO: <Original filename>"
            VALUE "ProductName", "TODO: <Product name>"
            VALUE "ProductVersion", "1.0.314.159"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END

You could use a pre-build step to create this file and it would get built in automatically. When you ask Windows for the version info, you see something like this:

Steve_Lionel_0-1745681791114.png

This data can also be retrieved with a call to a Windows API routine (GetFIleVersionInfo)

 

0 Kudos
Bryan_H_1
New Contributor I
2,209 Views

As a first test, I am trying to get the version information added to the EXE, then worry about dynamically updating it.  First added the example resource1.rc to the project.  After adding the existing item, it appears under the "resource files" folder in the project solution.  Next ran "Clean" then "Build".  The resulting EXE did not have any version information added to it.  The build log gave the following below.  Is there some additional configuration needed?

 

Compiling with Intel® Fortran Compiler Classic 2021.11.0 [IA-32]...
ifort /nologo /debug:full /Od /Qdiag-disable:10448 /warn:interfaces /module:"Debug\\" /object:"Debug\\" /Fd"Debug\vc170.pdb" /traceback /check:bounds /check:stack /libs:dll /threads /dbglibs /c /Qlocation,link,"C:\Program Files\Microsoft Visual Studio\2022-LTSC-17.8.9\VC\Tools\MSVC\14.38.33130\bin\HostX86\x86" /Qm32 "C:\Users\me.COMPANY\source\repos\VersionTest\VersionTest\Main.for"
Linking...
Link /OUT:"Debug\VersionTest.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"Debug\VersionTest.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Users\bryan.MBS\source\repos\VersionTest\VersionTest\Debug\VersionTest.pdb" /SUBSYSTEM:CONSOLE /IMPLIB:"C:\Users\bryan.MBS\source\repos\VersionTest\VersionTest\Debug\VersionTest.lib" -qm32 "Debug\Main.obj"
Embedding manifest...
mt.exe /nologo /outputresource:"C:\Users\me.COMPANY\source\repos\VersionTest\VersionTest\Debug\VersionTest.exe;#1" /manifest "Debug\VersionTest.exe.intermediate.manifest"

VersionTest - 0 error(s), 0 warning(s)

 

0 Kudos
andrew_4619
Honored Contributor III
2,203 Views

If you right click the RC in the solution explorer pane does it have a build instruction on the properties tab?

0 Kudos
Bryan_H_1
New Contributor I
2,200 Views

No.

 

In the Resource1.rc "Property Pages | Configuration Properties | Custom Build Step | General" are fields empty except the "Description" which has "Performing Custom Build Step...".

 

0 Kudos
andrew_4619
Honored Contributor III
2,190 Views

andrew_4619_0-1745850368085.pngandrew_4619_1-1745850386458.png

It needs to compile to make a .res

BTW I have never added this step it has been set up when the project is made.....

0 Kudos
Bryan_H_1
New Contributor I
2,182 Views

I believe it matches what you show.

 

VersionTest_Resources_General.png

VersionTest_Resources_CommandLine.png

0 Kudos
andrew_4619
Honored Contributor III
2,181 Views

so if you do a clean and then a build is it make the .res file?

 

0 Kudos
Bryan_H_1
New Contributor I
2,177 Views

After a clean and build there is no .res file.

Entire solution attached, if useful in troubleshooting.

0 Kudos
andrew_4619
Honored Contributor III
2,137 Views

andrew_4619_0-1745854070936.png

 

It threw a wobbler "can't open resource.h file", I opened the rc in a text ed, deleted the include lines for that at the top and did a rebuild. (X64 / iFX)

0 Kudos
andrew_4619
Honored Contributor III
2,134 Views

I think adding a "new" ie empty RC to the project and then in the VS resource editor adding a version object (control) is probably a better way to do this from the start.

0 Kudos
Bryan_H_1
New Contributor I
2,127 Views

Test 1:

--------

I commented out all 3 include lines, clean, rebuild.  No version info.

 

 

Test 2:

--------

Removed Resource1.rc

Created blank file Resource2.rc

Added existing item Resource2.rc

Double clicked Resource2.rc in solution explorer to open it in visual studio.

In the editor, Rt-clicked on Resourec2.rc | Add Resource

In the Add resource dialog double clicked "Version"

Clicked save all, I am given prompt:

      The resource script ... Resource2.rc was not created using Microsoft Visual Studio.  Comments, macros, preprocessor directives, and conditionally included information may be modified and/or removed from this file during the build process.  Replace existing file?

 

Selected "Yes"

Clean

Build

No version info.

Bryan_H_1_1-1745855136272.png

 

 

Test 3:

--------

Closed all open files in visual studio

Double clicked Resource2.rc in solution explorer

Get the following errors:

        error RC2144 : PRIMARY LANGUAGE ID not a number

        error RC2135: file not found: 1

        error RC2135: file not found: TEXTINCLUDE

        error RC2135: file not found: END

 

 

0 Kudos
andrew_4619
Honored Contributor III
2,093 Views

"Created blank file Resource2.rc", what is meant was under resources do "add"> "new item">"Resource File"> "add" . The system will create the resource file. 

 

0 Kudos
Bryan_H_1
New Contributor I
2,091 Views

"add"> "new item">"Resource File"> "add".  This gives:


    fatal error RC1015: cannot open include file 'winres.h'.

 

Is this a search path issue?

 

Questions:

1/ Where should this file be found?  (C:\Program Files\Microsoft Visual Studio\2022-LTSC-17.8.9\SDK\ScopeCppSDK\vc15\SDK\include\um\winres.h?)

2/ What controls where it searches?  (windows environment path variable?)

0 Kudos
andrew_4619
Honored Contributor III
2,027 Views

Those are questions that you should not need to answer. Your installation must be broken!

0 Kudos
Bryan_H_1
New Contributor I
2,025 Views

Good to know.  Should my next steps be:

1/ Uninstall Intel Fortran

2/ Uninstall Visual studio

3/ Uninstall Windows SDK

4/ Install Windows SDK

5/ Install Visual Studio

6/ Install Intel Fortran

0 Kudos
Steve_Lionel
Honored Contributor III
1,989 Views

When I tested this, I right clicked on the project, selected Add > New Item and selected Resource File.  I then opened the resource file, right clicked on Resource1.rc in the resource file, selected Add Resource > Version. By adding the resource file this way, it gets added to the project in a way that will get it compiled and linked in.

winres.h ought to be found from the list of folders under Include Files in the Intel Compilers and Libraries > IFX > Compilers dialog, but I've seen issues in the past where this was not honored by the resource compiler (part of Visual Studio's C++ support.) If for some reason this isn't working you can edit the .rc file and insert the complete path to the file.

0 Kudos
Bryan_H_1
New Contributor I
1,867 Views

Summary:

=========

Still no version information.

 

Questions:

=========

1/ Is there a way to know if the resource compiler was successfully run when compiling?

2/ Are there any special considerations/install order when I install Visual Studio, Windows SDK, and Intel Fortran so that versioning will work?

3/ Any suggestions on what should I try next?

 

Details:

=======

I tested adding the full path to all files referenced directly in the .rc file. Unfortunately, they referenced additional file dependencies.  Since I do not want to edit these files that are needed outside of my test project, I instead did a temporary desperate move and copied all files in the "C:\Program Files\Microsoft Visual Studio\2022\Preview\SDK\ScopeCppSDK\vc15\SDK\include\um\" folder and "C:\Program Files\Microsoft Visual Studio\2022\Preview\SDK\ScopeCppSDK\vc15\SDK\include\shared\" folder to be beside my Fortran source code for this project. 

Note: this is only temporary hack to try to bypass this search path problem in a proof of concept.

When this was done, I was able to Add > New Item and selected resource file, then opened the resource file, right clicked on Resource4.rc in the resource file, selected Add Resource > Version.  Before I couldn't even open the resource file in visual studio. So, this is progress!

However, when I tried to compile the program, it still does not contain any resource information.

At this point it feels like the resource compiler is not being invoked or did not run successfully.  Is there any way to determine if it was?  My guess is that something path related might be causing this too.

 

Also, I installed everything on a second machine recently, and when I tested on that machine, I am getting the same issue with the resource file #include references not being found.  So, it seems that how I installed things was incorrect, or both machines had their installs corrupted, at least as far as the paths needed for resource files are concerned. 

Any gotchas I need to watch out for when I try to re-install again?

 

0 Kudos
andrew_4619
Honored Contributor III
1,862 Views

andrew_4619_0-1746034575506.png

If you clean and build you should see it as above. It makes a .res file

On my windows 11 VS2022 system it installed the SDK at C:\Program Files (x86)\Windows Kits\10

You should not need to install the SDK. When you install the C++ components with VS you get the sdk and resource editor/ compiler etc 

 

0 Kudos
Bryan_H_1
New Contributor I
1,868 Views

1/ Resource compiler not listed in Build output:

 

Bryan_H_1_1-1746038577833.png

 

 

2/ SDK path exists

 

Bryan_H_1_2-1746038577834.png

 

 

3/ Visual Studio installer when I ran it in modify mode, shows "Desktop development with C++" is already installed.

 

Bryan_H_1_3-1746038577835.png

 

 

0 Kudos
Reply