How can you automatically update a .NET project COM reference?

1.8k views Asked by At

I have a legacy VB6 COM DLL that's included as a reference in a .NET project. My manual build process looks like this:

  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

I'm in the process of automating this procedure. Steps 4 through 6 are giving me troubles. When I register the new VB6 COM DLL, the old reference in the .NET project is invalid. By looking in the project file, I see this:

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

I believe I need to automatically overwrite the Guid property with the COM's new clsid, and I may need to change the VersionMajor and VersionMinor properties.

Unfortunately these don't seem to be properties of the VB6 COM DLL file. Where can I get this information and/or am I even going down the right path? Is there some tool or option that will automatically do this for me?

Edit

The build error I get if I don't update the reference is error MSB3179.

The actual text of the error message is:

c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(2580,9): error MSB3179: Problem isolating COM reference 'DllName': No registered classes were detected for this component. [path/to/projfile.vbproj]

... where "DllName" is my DLL name and "path/to/projfile.vbproj" is the fully qualified path to the project file with the COM reference.

1

There are 1 answers

2
Joe On

I've not tried this, but you may be able to achieve this by generating an interop assembly explicitly using tlbimp, rather than letting Visual Studio do it for you by adding a reference to the COM DLL.

Something like:

  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

Using your method, I'm no longer using Registration-Free COM

I don't have much experience with Reg-free COM, but maybe you can manually generate the manifest with a command-line tool instead of setting the Isolated property - e.g. using the MT.EXE tool described in this answer.