Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typelib Generation and Installation with WiX

Tags:

After asking about what Visual Studio does to register a COM Library, it became clear that VS did two things for COM registration:

  1. Registered the COM Library
  2. Creates and registers a Type Library

Visual Studio seems to do this registration using regasm.exe. For the first part (the direct COM registration) using tallow or heat (WiX 2.0 or WiX 3.0) seems to get all of the basic COM registration information correct.

However, what tallow/heat doesn't seem to do is set up a type library installation. It would be possible to create a custom action to do this with a WiX installer and regasm.exe, but invoking custom actions are not best practices when it comes to Microsoft installer based installers.

Upon further research, it looks like an msi has the ability to generate the type library upon installation. In fact, WiX seems to have direct support for it! In a file element, you can add a Typelib element. In fact, an article over here on wix has an example of filling out the TypeLib element with Interface elements.

It seems there's at least two required attributes to an Interface element:

  1. Id
  2. Name

Larry Osterman speaks about the other parts of the interface that need to be registered for a TypeLib in general, and this Interface entry seems to take care of the individual parts. Larry says we need to specify the ProxyStubClassId32 as "{00020424-0000-0000-C000-000000000046}", so we can easily add that.

Where to go from there and what to fill out for the various Interface elements has me stumped. I've gone ahead and added the TypeLib element to my wix file, and it successfully compiles. I'm a bit clueless as to how to set up the Interface elements though. What do we need to do to properly fill out the TypeLib element, and what apps or tools can I use to get it?

The answer below by wcoenen looks promising...I'm going to give it a shot.

Update: Posted my final solution below as an answer.

like image 430
Robert P Avatar asked Feb 20 '09 01:02

Robert P


People also ask

What is WiX Installer used for?

Windows Installer XML Toolset (WiX, pronounced "wicks"), is a free software toolset that builds Windows Installer packages from XML. It consists of a command-line environment that developers may integrate into their build processes to build MSI and MSM packages.

How do I create a WiX Windows Installer?

Go to Tools -> WiX Setup Editor. On the left under Root Directory choose InstallFolder. Under Projects to install, choose the project you want to install. In the red area to the right, you'll see a list of files.


2 Answers

Here's the lazy man's way of solving this problem: Use heat from WiX 3.0.

If you have a type library generated automatically and installed via regasm, heat can take the .tlb as an argument in

heat file c:\my\path\to\my.tlb -out tlb.wxs 

It will generate all the typelib and interface elements you need to register. This won't solve the problem of needing to know them ahead of time, and it won't solve the problem of GUIDs changing when the version of the assembly changes (even if the interface doesn't - which is the only time you're supposed to change it) but it will get you partway there.

like image 155
Robert P Avatar answered Oct 21 '22 03:10

Robert P


The following trick can help with harvesting any registry changes and turning them into a wxs file, including the typelib element you're after.

  1. First, bring your registry back in a state where the type library was not registered:

    c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe /tlb /u mylib.dll 
  2. Export this clean state of the registry to hklm-before.reg:

    c:\WINDOWS\system32\reg.exe export HKLM hklm-before.reg 
  3. Register the type library again:

    c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe /tlb mylib.dll 
  4. Export the new state of the registry to hklm-after.reg:

    c:\WINDOWS\system32\reg.exe export HKLM hklm-after.reg 
  5. Now we have two text files, hklm-before.reg and hklm-after.reg. Create a diff.reg file which only holds the relevant differences between these. You can find the differences easily with a diffing tool. I like to use the diff tool included in TortoiseSVN since I already use that every day. (WinDiff doesn't seem to work well in this case because of text-encoding issues.)

  6. We can now convert diff.reg into a .wxs by calling heat.exe with the reg command. (Requires wix 3.5 or newer.)

    heat reg diff.reg -out typelib.wxs 
like image 23
Wim Coenen Avatar answered Oct 21 '22 03:10

Wim Coenen