Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register a .NET COM DLL during Wix Install

Tags:

wix

Background:

Our application is a plugin for a much larger application. Everything we create are DLL files that the larger application hooks to. Because of this our .NET (C#), DLL files must be registered for a COM interface.

We have a working InstallShield project, but for many reasons which I won't go into here, we wish to migrate it to WiX. The only thing left to be done for the installer is to register our DLL files for COM.

Problems

Here is a sample component with a single DLL file.

<Component Id="MyComponent" Guid="COMPONENT-GUID" SharedDllRefCount="yes" >
    <File Id="MyDLL.dll" Name="MyDLL.dll" KeyPath="yes" Assembly=".net" 
          AssemblyManifest="MyDLL.dll" AssemblyApplication="MyDLL.dll" />
</Component>

As per the accepted answer of How do you register a Win32 COM DLL file in WiX 3?, it is recommended to add SelfRegCost=1 to the File tag. This results in an error during install:

Module C:\Program files\Product\MyDll.dll failed to register. HRESULT -2147024769. Contact your support personnel.

The second answer in the same question (by Rob Menshing) recommends against this approach, but to add inside the file tag this:

<Class Id="PUT-CLSID-HERE" Context="InprocServer32" ThreadingModel="apartment" Description="Your server description">
        <ProgId Id="Your.Server.1" Description="Your ProgId description">
            <ProgId Id="Your.Server" Description="Your ProgId description" />
        </ProgId>
    </Class>

    <Class Id="PUT-PROXY-CLSID-HERE" Context="InprocServer32" ThreadingModel="both" Description="Your server Proxies, assuming you have them">
        <Interface Id="PUT-INTERFACEID-HERE" Name="IInterface1" />
        <Interface Id="PUT-INTERFACEID-HERE" Name="IInterface2" />
        <Interface Id="PUT-INTERFACEID-HERE" Name="IInterface3" />
        <Interface Id="PUT-INTERFACEID-HERE" Name="IInterface4" />
    </Class>

I am a bit confused as to put in as the CLSID ids. I put in a generated GUID and installed it. It installed fine, but the larger application could not find the DLL files. (I used the interface tags generated from heat.exe.)

Another approach found in the same question (by Adan Tegen) recommends using heat.exe file myDll.dll -out my.wxs

Using the output, I add this to the File tag:

<TypeLib Id="Another Guid" Language="0" MagorVersion="1">
    <!--Interfaces generated from heat.exe-->
</TypeLib>

Every way I have tried to register .NET for COM has failed and after reading so many questions about the topic I am no closer to knowing the correct way of doing it. What should I do? Why is this such a difficult task when everything else in WiX has been fairly simple?

I should mention that the original InstallShield project created a custom action that would call regasm.exe. If all else fails that could be a possibility, but I would rather do things right.

I just found that heat.exe file myDll.dll -scom -o myDll.wxs outputs registry values similar to what I need. Now, how do I reference the newly created component inside the DLL component?

like image 535
SaulBack Avatar asked Oct 18 '11 21:10

SaulBack


1 Answers

I just found that heat.exe file myDll.dll -scom -o myDll.wxs outputs registry values similar to what I need.

Are you sure about -scom there? AFAIK, that option actually suppresses COM registration!

Now how do I reference the newly created component inside the DLL component?

The component generated by heat.exe already includes a File element for the DLL. So it actually contains everything needed to install and register the DLL file. You don't need the original "DLL component".

If you need to put the file and its COM registration in separate components, then you will have to remove the File element from the component generated by heat.exe.

Also, components cannot reference other components. You can have references between ComponentGroups though, something that we use heavily in our wixlibs to model dependencies, but that's a rather advanced use case.

like image 165
Wim Coenen Avatar answered Sep 22 '22 14:09

Wim Coenen