FileVersionInfo retrieving incorrect file version

廉价感情. 提交于 2020-01-25 18:54:06

问题


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!!


回答1:


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.



来源:https://stackoverflow.com/questions/11498744/fileversioninfo-retrieving-incorrect-file-version

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!