1

I am trying to read the file version from an exe file. ( - not product version.) I tested two sample codes.

var versionInfo = FileVersionInfo.GetVersionInfo(FilePath);
string Description = versionInfo .FileDescription;
string Company = versionInfo.CompanyName;
//1
string Fileversion1 = string.Format("{0}.{1}.{2}.{3}", versionInfo.FileMajorPart, versionInfo.FileMinorPart, versionInfo.FileBuildPart, versionInfo.FilePrivatePart);
//2
string Fileversion2 = versionInfo.FileVersion;

The result is shown below.

enter image description here

The following figure is an actual property of PowerShell.

enter image description here

MS applications such as notepad, cmd will get the same results as POwershell.

Check Putty with the same code:

enter image description here

I would like to know the file version in the properties of the application.

I have a history of upgrading from Windows8 to Windows10 through a free upgrade to Windows10. Can this behavior affect the outcome?

cskang
  • 93
  • 6
  • [What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?](https://stackoverflow.com/questions/64602/what-are-differences-between-assemblyversion-assemblyfileversion-and-assemblyin) – Jimi Nov 15 '18 at 08:37
  • I cannot reproduce this on my Win10 installation. `FileVersionInfo.GetVersionInfo(@"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe")` gives `10` for the `FileMajorPart`. Check if your application has some app compat setting applied to it -- if possible, rebuild it somewhere else, rename it, and make sure there are no compatibility settings applied. – Jeroen Mostert Nov 15 '18 at 08:46
  • @Jeroen Mostert The OP probably has the April 2018 PowerShell update. That will return a Major version as reported. – Jimi Nov 15 '18 at 09:21
  • 1
    This is normal for Win10. It used to be that the appcompat team at Microsoft had to test tens of thousands of commonly used programs, creating an appcompat shim if the program refused to run on a higher version number. They gave up on that for Win10, it stopped being practical. It won't lie about the version number if your program was built to target Win10. Awkward to do in C#, you have to run Editbin.exe to patch the file header, /subsystem option. But your program will now only run on Win10. – Hans Passant Nov 15 '18 at 10:19

1 Answers1

1

The documentation of property FileVersion is misleading. It makes you think it is a concatenation of major, minor, build and private numbers.

Actually, FileVersion is extracted using a call to a system API function (VerQueryValue), which can returns something different.

Nick
  • 4,787
  • 2
  • 18
  • 24
  • It's best read in conjunction with the doco for resource files, which explain that there's a _binary_ `FILEVERSION` property, that breaks down into 4 words, and that there is _also_ a separate _string_ `FileVersion` property, and they aren't required to match and the string form is not required to be four numbers. For added fun: Explorer doesn't display the string form for file versions, but does display the string form for product versions. As long as the code pages match. – JdeBP Jul 11 '23 at 07:37