How can tlbimp be used to specify different File and Assembly versions?
Asked Answered
C

2

9

We are using tlbimp to generate interop assemblies. We would like to stamp the interop assemblies with both a File Version and an Assembly Version. However, the /asmversion option on tlbimp seems to be setting both of these to the same value.

Does anyone know how to set up different File and Assembly versions on an interop assembly using tlbimp?

Calamander answered 28/3, 2011 at 6:47 Comment(4)
Great question, but why exactly do you need this ability?Agonizing
We want to keep the assembly version the same between releases (because the new assembly is still compatible with existing clients), but we would like our installer to replace an old version of the assembly with a newer (e.g. bugfix) one (and the installer uses the FileVersion for this).Calamander
I see, that's quite reasonable.Agonizing
So why the bounty now?Eighteenth
C
7

In the end we found a couple of links about a project called tlbimp2 on codeplex, and compiled our own modified version of tlbimp2:

  1. http://clrinterop.codeplex.com/discussions/208832
  2. http://clrinterop.codeplex.com/SourceControl/changeset/view/39798

I took the code from the tlbimp project of 2. and modified it along the lines of 1. There were a couple of problems we had to work around:

In TlbImp.cs I had explicitly to assemble the file version number from the result of FileVersionInfo.GetVersionInfo, since the FileVersion property was empty:

    if (Options.m_strFileVersion == null)
    {
        // get the fileversion
        var versionInfo = 
            FileVersionInfo.GetVersionInfo(Options.m_strTypeLibName);
        Options.m_strFileVersion = 
            versionInfo.FileMajorPart 
            + "." + versionInfo.FileMinorPart 
            + "." + versionInfo.FileBuildPart 
            + "." + versionInfo.FilePrivatePart;
    }

In tlbimpcode.cs I had to switch:

 AsmBldr.DefineVersionInfoResource(
   strProduct, 
   strProductVersion, 
   strCompany, 
   strCopyright, 
   strTrademark);

to:

 AsmBldr.DefineVersionInfoResource();

Or the custom resources would not be used.

Hope this helps someone else with the same problem.

Calamander answered 31/3, 2011 at 21:44 Comment(0)
B
1

It seems pretty unlikely you'll be able to do this using only tlbimp. You'll probably have to mess with the IL. You'll need to add something along the lines of:

  .custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 0B 33 2E 35 2E 35 30 32 31 31 2E 31 00 00 ) // ...3.5.50211.1.. 

The format is 01 NN NN SS1 ... SSN 00 00.

NN NN is the length of the string, SS comprises the ascii bytes representing the version.

Boatswain answered 29/3, 2011 at 23:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.