4

I'm attempting to use C# and System.Diagnostics.FileVersionInfo to extract the version information from a list of files. My purpose for doing this is to keep track of unique filepath and version combinations. When the files change I'd like various things to happen depending on what exactly changed.

I've used both the FileVersion and ProductVersion properties of FileVersionInfo to no avail. Both report a different version number than what is reported in explorer.

An example using explorer.exe

Explorer Details tab reports: "6.1.7601.17567" (for both File and Product)
FVI.ProductVersion reports: "6.1.7600.16385"
FVI.FileVersion reports: "6.1.7600.16385 (win7_rtm.090713-1255)"
Shimmy Hacked
  • 459
  • 5
  • 10
Vitus
  • 43
  • 2

1 Answers1

4

For some reason the ProductVersion property doesn't match the ProductMajorPart/MinorPart/BuildPart/PrivatePart... To get the actual version you can do this:

var fvi = FileVersionInfo.GetVersionInfo(path);
var productVersion = new Version(
                           fvi.ProductMajorPart,
                           fvi.ProductMinorPart,
                           fvi.ProductBuildPart,
                           fvi.ProductPrivatePart);
var fileVersion = new Version(
                           fvi.FileMajorPart,
                           fvi.FileMinorPart,
                           fvi.FileBuildPart,
                           fvi.FilePrivatePart);
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
  • Worked Perfectly. Thanks. The infinite wisdom of Microsoft. – Vitus Dec 21 '11 at 02:11
  • 1
    The "some reason" is that there are separate string and binary forms of the property in the resource compiled into the executable, and there's no requirement that the string form match the binary form. Which it doesn't in the question. The string form has all of that `(win7_rtm.090713-1255)` on the end, notice, and clearly a different third and fourth numeric part. – JdeBP Jul 11 '23 at 07:26