I have scripted an installer using NSIS and added version information via VIProductVersion
and VIAddVersionKey
commands. When I view the properties of the compiled file, the version information is there as I expect it to be.
My problem is when I attempt to get the version information via the C# command FileVersionInfo.GetVersionInfo(fileName).FileVersion
, it returns an empty string.
Here is a quick way to replicate:
NSIS Script
!include LogicLib.nsh
!include FileFunc.nsh
!define PRODUCT_NAME "Installer"
!define PRODUCT_VERSION "1.0.0.2"
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
VIProductVersion "${PRODUCT_VERSION}"
VIAddVersionKey ProductVersion "${PRODUCT_VERSION}"
OutFile "Setup.exe"
Section "Installer"
SectionEnd
C# Code
class Program
{
static void Main(string[] args)
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo("Setup.exe");
if (fvi != null)
{
Console.WriteLine(string.Format("File Version: {0}", fvi.FileVersion));
}
else
{
Console.WriteLine("Could not load file version info");
}
Console.WriteLine("Press any key to continue...");
Console.Read();
}
}
This gives the output of:
File Version:
Press any key to continue...
What do I need to get to read the FileVersion
as 1.0.0.2
?
I figured out what I was doing wrong. Even though it looked correct in the properties dialog, I was using the wrong value with VIAddVersionKey
. To have it read correctly, you should use VIAddVersionKey FileVersion "${PRODUCT_VERSION}"