English 中文(简体)
您如何自动更新.NET 工程 COM 参考?
原标题:How can you automatically update a .NET project COM reference?

我有一个遗留的 VB6 COM DLL, 它包含在一个.NET 项目中作为参考。 我的手工构建过程是这样的:

  1. Build VB6 DLL
  2. Copy VB6 DLL to reference directory
  3. Register VB6 DLL with regsvr32
  4. In the .NET project, remove the old reference
  5. Add reference to new VB6 DLL (browse)
  6. Set the Isolated property of the reference to True
  7. Build .NET solution

正在使此程序自动化。 步骤 4 至 6 正在给我带来麻烦。 当我注册新的 VB6 COM DLL 时,. NET 工程中的旧引用无效 。 通过查看工程文件, 我可以看到 :

<ItemGroup>
  <COMReference Include="DllName">
    <Guid>{65CDCC83-E707-4AA3-8940-FE79F265D570}</Guid>
    <VersionMajor>50</VersionMajor>
    <VersionMinor>0</VersionMinor>
    <Lcid>0</Lcid>
    <WrapperTool>tlbimp</WrapperTool>
    <Isolated>True</Isolated>
    <EmbedInteropTypes>True</EmbedInteropTypes>
  </COMReference>
</ItemGroup>

我认为,我需要用 COM 的新密钥自动覆盖 < code> Guid 属性,我可能需要更改 < code> VersionMajor < /code > 和 < code> Version Minor 属性 。

不幸的是,这些似乎不是 VB6 COM DLL 文件的属性。 我从哪儿可以得到这些信息和/或我是否正在沿着正确的路径走下去? 是否有任何工具或选项可以自动为我做到这一点?

< 强力 > 编辑 < /强 >

如果我不更新引用,我就会发现错误的构建错误 MSB3179

错误信息的实际文本是:

c: Windows Microsoft.NETFramrework64v4.0.30319Microsoft.Common.targes(2580,9):错误 MSB3179: 问题分离 COM 参考 DllName: 未检测到此组件的注册分类 。 [path/to/ projfiles.vbproj]

...“ DllName” 是我的 DLL 名称, 而“ path/to/ projfile.vbproj” 是使用 COM 引用的完全合格的工程文件路径 。

问题回答

我没有尝试过这一点,但你也许能够实现这一点,方法是生成一个明确使用 tlbimp 的对接组合,而不是让视觉工作室为您这样做,增加对 COM DLL 的引用。

类似 :

  1. Build VB6 DLL
  2. Copy VB6 DLL to reference directory
  3. Run tlbimp (e.g. from a batch file) to generate an interop assembly in the reference directory.
  4. The .NET project should have a reference to the interop assembly output at step 3.
  5. Build .NET solution

使用您的方法, 我不再使用无注册 COM

我对Reg-free COM没有多少经验,但也许你可以用一个命令线工具手动生成清单,而不是设置孤立财产——例如,使用<这一答复中描述的MT.EXE工具。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签