开发者

Get Custom File Version Info from a Native binary using C#

I've got a bunch of native (C++) binaries that I want to scan and retrieve version information about from a C# console application. Using System.Diagnostics.FileVersionInfo I am able to get the actual version strings, company name, etc. However there is a "Build Date" string in there (which is shown by the Windows File Properties "Version" tab), and it is not being retrieved by FileVersionInfo.

It seems that "Build Date" is technically custom data placed in the file, which I guess would be why I FileVersionInfo does not automatically grab this data, but is there any way to get these custom values?

In the native binaries, the "Build Date" string is included via an .RC file, using the following section:

BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904e4"
        BEGIN
            VALUE "Build Date", "11/03/2009"
            VALUE "CompanyName", "My Company "
            VALUE "FileDescription", "My DLL"
            VALUE "FileVersion", VERSTR
            VALUE "InternalName", "MyCode.dll"
            VALUE "LegalCopyright", "Copyright © Me"
            VALUE "ProductVersion", VERSTR
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409开发者_StackOverflow, 1252
    END
END

I am then trying to retrieve the information in C# like this:

FileVersionInfo ver = FileVersionInfo.GetVersionInfo(path);
Console.WriteLine(ver.ToString());


If the FileVersionInfo class doesn't do want you want, you can always turn to the native version info APIs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜