Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 663
dominic Avatar asked Mar 28 '11 06:03

dominic


People also ask

What does Tlbimp do?

Remarks. Tlbimp.exe performs conversions on an entire type library at one time. You cannot use the tool to generate type information for a subset of the types defined within a single type library. It is often useful or necessary to be able to assign strong names to assemblies.

How do I create an interop file?

There are two ways to generate a primary interop assembly: Using the Type Library Importer (Tlbimp.exe) provided by the Windows SDK. The most straightforward way to produce primary interop assemblies is to use the Tlbimp.exe (Type Library Importer).

Where can I find Tlbimp exe?

Navigate to C:\Program Files\Microsoft SDKs\Windows\vx. x\Bin in which the earlier . NET Framework version of TlbImp.exe is installed.


Video Answer


2 Answers

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.

like image 165
dominic Avatar answered Sep 28 '22 02:09

dominic


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.

like image 32
smarcellus Avatar answered Sep 28 '22 03:09

smarcellus