FileVersionInfo.FileVersion returns ProductVersion?

后端 未结 2 2069
名媛妹妹
名媛妹妹 2020-12-22 07:01

I am trying to get the file version using C#:

string file = @\"C:\\somefile.dll\";
Console.WriteLine(FileVersionInfo.GetVersionInfo(file).FileVersion);
         


        
2条回答
  •  有刺的猬
    2020-12-22 07:26

    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);
    

提交回复
热议问题