如何使用tlbimp指定不同的File和Assembly版本?

dom*_*nic 9 .net com-interop tlbimp

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

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

dom*_*nic 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;
    }
Run Code Online (Sandbox Code Playgroud)

在tlbimpcode.cs我不得不切换:

 AsmBldr.DefineVersionInfoResource(
   strProduct, 
   strProductVersion, 
   strCompany, 
   strCopyright, 
   strTrademark);
Run Code Online (Sandbox Code Playgroud)

至:

 AsmBldr.DefineVersionInfoResource();
Run Code Online (Sandbox Code Playgroud)

或者不使用自定义资源.

希望这可以帮助其他人解决同样的问题.