I have a legacy VB6 COM DLL that's included as a reference in a .NET project. My manual build process looks like this:
- Build VB6 DLL
- Copy VB6 DLL to reference directory
- Register VB6 DLL with
regsvr32
- In the .NET project, remove the old reference
- Add reference to new VB6 DLL (browse)
- Set the Isolated property of the reference to True
- 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.
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:
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.