9

我们正在使用 tlbimp 生成互操作程序集。我们想用文件版本和程序集版本标记互操作程序集。但是, tlbimp 上的 /asmversion 选项似乎将这两个设置为相同的值。

有谁知道如何使用 tlbimp 在互操作程序集上设置不同的文件和程序集版本?

4

2 回答 2

7

最后,我们在 codeplex 上找到了一些关于名为 tlbimp2 的项目的链接,并编译了我们自己的修改版 tlbimp2:

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

我从 2 的 tlbimp 项目中获取了代码,并按照 1 的方式对其进行了修改。我们必须解决几个问题:

在 TlbImp.cs 中,我必须从 FileVersionInfo.GetVersionInfo 的结果中明确组装文件版本号,因为 FileVersion 属性为空:

    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;
    }

在 tlbimpcode.cs 我不得不切换:

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

至:

 AsmBldr.DefineVersionInfoResource();

否则不会使用自定义资源。

希望这可以帮助其他有同样问题的人。

于 2011-03-31T21:44:53.433 回答
1

仅使用 tlbimp 似乎不太可能做到这一点。您可能不得不与 IL 混淆。您需要添加以下内容:

  .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.. 

格式为01 NN NN SS1 ... SSN 00 00.

NN NN 是字符串的长度,SS 包含表示版本的 ascii 字节。

于 2011-03-29T23:39:24.370 回答