开发者

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 开发者_StackOverflowup different File and Assembly versions on an interop assembly using tlbimp?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜