5

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?

rpetti
  • 607
  • 6
  • 10

4 Answers4

11

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
  • 607
  • 6
  • 10
  • 3
    What’s `BLOCK "040904E4"`? Is that a magic number? Maybe you want to link to a good resource for RC-file definitions!? – Kissaki Dec 06 '11 at 08:45
  • 1
    A quick Google search for that magic number reveals that it's used for specifying the language settings for the strings: `BLOCK "040904E4" // Lang=US English, CharSet=Windows Multilingual` Unfortunately I haven't been able to find any other documentation on it. – rpetti Dec 21 '11 at 18:47
  • There are [bits of documentation](http://msdn.microsoft.com/en-us/library/windows/desktop/ms647464(v=vs.85).aspx) in the corresponding APIs. – Georg Fritzsche Dec 13 '12 at 18:46
  • 1
    I found the doc page: http://msdn.microsoft.com/en-us/library/windows/desktop/aa381049%28v=vs.85%29.aspx Relevant quotes: "0x0409 U.S. English" and "1252 Multilingual" (1252 = 0x04E4). – Mattias Andersson Aug 30 '13 at 22:27
3

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
  • 53,078
  • 22
  • 114
  • 136
  • This is an ok solution, but most of our binaries are not actually .NET, is there something more general? – rpetti Jun 10 '09 at 14:45
  • Oh, they are C++. This is a fine question, I too would like to know the answer. – stimms Jun 10 '09 at 14:52
1

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
  • 1,589
  • 1
  • 14
  • 26
0

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
  • 39,849
  • 11
  • 94
  • 127