-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Description
There is an undocumented behavior difference in FileVersionInfo.GetVersionInfo, where the Windows version calls GetFileVersionInfoEx (which looks at the VsVersionTable) and the *nix version just parses the managed metadata. This means you get different results depending on OS if the binary is unmanaged, or the managed and unmanaged metadata differs.
There's an issue filed with the API docs to document this, and this issue was reported earlier in #40895 (which was closed after VsVersionTable and managed metadata was made to match, instead of fixing the parsing.)
Reproduction Steps
FileVersionInfo.GetVersionInfo("unmanaged.exe"); // Where 'unmanaged.exe' is any unmanaged PE executable (including DLL)
Expected behavior
Same values are returned on both Linux and Windows for both managed and unmanaged binaries.
Actual behavior
On Linux, unmanaged binaries won't have values set, and managed binaries will have values set to the managed metadata. On Windows, values will always be set to the VsVersionTable.
Regression?
No.
Known Workarounds
Use a third-party full PE parser like PeNet to manually get the values from the VsVersionTable.
Configuration
.NET 8, both Windows and Linux, x64. Not specific to the configuration, other than it being a platform difference.
Other information
Implementation lives in /src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Unix.cs and FileVersionInfo.Windows.cs.
In general, it's very unclear what FileVersionInfo is supposed to support, because all the documentation is as-is from the .NET Framework version. Should it support Windows binaries outside Windows? Should it be limited to the OS it's built for, in which case, should it support something like UAPI.8 Package Metadata?