FileVersionInfo retrieving incorrect file version

2019-09-18 02:20发布

I have to retrieve values under details tab e.g, File version, Product Version for .dll and .exe files through C#. I'm using the following code for this.

     FileVersionInfo myFile = FileVersionInfo.GetVersionInfo('Name of the file');
     //File Version
     string fileVersion = myFile.FileVersion;

The issue with this code is that it gives incorrect file version for some files. Details tab of these files shows different file version and code retrieves incorrect value. I'm not sure why this is happening.

Please help. Thanks in advance!!

标签: c# .net dll
1条回答
啃猪蹄的小仙女
2楼-- · 2019-09-18 02:57

expected version(from Explorer) is 10.0.0.35 and i got 10.0.000.0035

That's the same number. The file version number appears in the native resource twice. Something you can also see when you edit a version resource in a C++ program. There's a human readable version with no restrictions on the format. That's what you are reading, note how FileVersionInfo.FileVersion returns a string.

And there's a machine readable version, a 64-bit number. With 16-bits each for the 4 parts. Which is what Explorer is reading. The corresponding properties are FileMajorPart, FileMinorPart, FileBuildPart and FilePrivatePart. Note how they return an int.

ProductVersion has this too.

查看更多
登录 后发表回答