FileVersionInfo.FileVersion returns ProductVersion?

廉价感情. 提交于 2019-11-29 18:09:01

It seems Windows Explorer are stripping leading 0s of the version parts.

Try creating an assembly with FileVersion 001.001.001.001, it will show as 1.1.1.1 in explorer. But your code would return the actual value (001.001.001.001).

EDIT:

Explorer will return 001.001.001.001 as ProductVersion, but only if AssemblyInformationalVersion isn't set, in which case it would return that as ProductVersion.

The reason is, in WIN32 API (and the file metadata), product versions are defined as string but file versions are defined as integer while in .NET, all of them are defined as integer.

If you use reflector and inspect FileVersionInfo class, you can see that they are loaded differently:

 this.productVersion = GetFileVersionString(memIntPtr, string.Format(CultureInfo.InvariantCulture, format, new object[] { codepage, "ProductVersion" }))

But:

this.fileMajor = HIWORD(fixedFileInfo.dwFileVersionMS);
this.fileMinor = LOWORD(fixedFileInfo.dwFileVersionMS);
this.fileBuild = HIWORD(fixedFileInfo.dwFileVersionLS);
this.filePrivate = LOWORD(fixedFileInfo.dwFileVersionLS);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!