views:

251

answers:

4

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 company etc... We would like to put this into our automated compilation system. Getting this version information into the binary after the binary is compiled is preferable, but any information on how this is done would be helpful. And of course, this needs to be programmatic; we can't be bothered to manually enter the information into a resource hacker for 5000 binaries every day.

Has anyone ever done this before? How could it be done?

+2  A: 

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" )]
tanascius
This is an ok solution, but most of our binaries are not actually .NET, is there something more general?
rpetti
Oh, they are C++. This is a fine question, I too would like to know the answer.
stimms
A: 

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"

John Weldon
+4  A: 

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.

rpetti
This solution should be marked as the correct one
Daniel Albuschat
+1  A: 

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.

Harold Bamford