How do I embed version information into a windows binary?

前端 未结 4 832
有刺的猬
有刺的猬 2021-01-19 04:31

You probably know that Windows has that option where you can view the properties of a binary and it will display information about the author, the version number, the compan

相关标签:
4条回答
  • 2021-01-19 04:49

    Assuming windows PE binaries, the Version information is stored in the PE header, in the IMAGE_OPTIONAL_HEADER section under the locations:

    WORD MajorImageVersion
    WORD MinorImageVersion
    

    About which this documentation says:

    A user-definable field. This allows you to have different versions of an EXE or DLL. You set these fields via the linker /VERSION switch. For example, "LINK /VERSION:2.0 myobj.obj"

    0 讨论(0)
  • 2021-01-19 05:00

    This just showed up on CodeProject yesterday:

    Simple Version Resource Tool for Windows

    It is a command line tool, but it should be easily operated from a script.

    0 讨论(0)
  • 2021-01-19 05:01

    Look for an AssemblyInfo.cs to your project.

    But this it has to be filled out before compilation. But you can share one AssemblyInfo.cs between many binaries. And you are not bound to this exact filename - so you can split the information into more files ... one general file about the company, one about the product, one for the binary's version number.

    / Individual Information
    [assembly: AssemblyTitle( "" )]
    [assembly: AssemblyDescription( "" )]
    
    // Version information
    [assembly: AssemblyVersion( "1.0.*" )]
    [assembly: AssemblyInformationalVersion( "1.0.0.0" )]
    
    // General Information
    [assembly: AssemblyConfiguration( "" )]
    [assembly: AssemblyCompany( "" )]
    [assembly: AssemblyProduct( "" )]
    [assembly: AssemblyCopyright( "" )]
    [assembly: AssemblyTrademark( "" )]
    [assembly: AssemblyCulture( "" )]
    [assembly: NeutralResourcesLanguage( "en" )]
    
    0 讨论(0)
  • 2021-01-19 05:07

    It looks as though the best solution (for us at least) is to use an RC file.

    1 VERSIONINFO
    BEGIN
        BLOCK "StringFileInfo"
        BEGIN
            BLOCK "040904E4"
            BEGIN
                VALUE "File Version",      "1.0.4"
                VALUE "Build Number",     "3452"
            END
        END
    END
    

    Which is compiled into a .res file

    rc.exe /fo Results/version.res version.rc
    

    Which is then linked in with the rest of the object files.

    0 讨论(0)
提交回复
热议问题