title: Replicating Visual Studio COM registration with a WiX Installer
body: <p>Once upon a time, a young, naive engineer thought it would be a good idea to separate out some of the functionality for his app into a COM component, written in C#.  Visual studio had all the tools to do that, right?  .NET was practically made for this, right?  HA!  He said, this will be easy.  I'll have decent separation of components, keeping business logic away from the front end, and with COM, I'll be able to use it from anywhere!  He merrily checked the <code>register for COM interop</code> checkbox in the project properties, exposed the classses he wanted, and went on his way.</p>
  
  <p>Oh, the trials such a choice made.  The young engineer now, more experienced, would not now wish this upon anyone.  However, the burden had been placed upon his shoulders, and the burden remained heavy.  He looked to lighten the load.</p>
  
  <p>Along came WiX, a tool for generating Windows Installer files from XML.  This intrigued him - it could replicate, quite simply, most of the code needed for a proper windows installer file simply from a handful of configuration files.  His sights were looking up.</p>
  
  <p>With WiX 2.0, he could generate quite easily the files needed to register a C# COM object.  This involved using the tool tallow.  He'd do something like the following:</p>
  
  <pre><code>tallow -c -nologo MyComExposedLibrary.dll &gt; MyComExposedLibrary.wxs
  </code></pre>
  
  <p>which would then be fixed up (at first this was done manually, but eventually I recorded the steps into a small tool set the final directory ref id, component ID, fileID, GUID and codebase).</p>
  
  <p>Then, the ensuing installer would install, and there would be joyous celebration, if the app worked.</p>
  
  <p>Which it did not.</p>
  
  <p>For days the young engineer poured over the differences on his development PC and that of the test install PC.  "All the registry keys are the same!" He would exclaim.  "Everything for MyComExposedLibrary is registerd, I swear!"</p>
  
  <p>Except, it wasn't.</p>
  
  <p>On the dawn of third day, after many a mountain dew, he realized there was one more object that Visual Studio was registering that his installer was not: the MyComExposedLibrary.tlb file.</p>
  
  <p>Visual Studio, apparently, had been registering this file all along, creating additional subkeys in the <code>HKLM\Software\Classes\Interface</code> registry key, and registering the typelib in <code>HKLM\SOFTWARE\Classes\TypeLib</code>.</p>
  
  <p>Tallow gave no help, complaining that a .tlb wasn't a file it groked.  Nor the WiX 3.0 beta - this seemed to have even more issues getting things working.</p>
  
  <p>I also gave Heat a try.  This generated registry elements and class elements.  I cleaned up heat's output, and then went to compile it, but got a different error: <code>error LGHT0130 : The primary key &lt;uuid here&gt; is duplicated in table 'Registry'</code>.   Problem is, as far as I can tell, that uuid doesn't actually exist in any of my wxs source files.  If I change around the component ref order in my feature element, a different dll component gives that error.  Since I have been unsuccessful at getting a WiX 3.0 version of the project to compile, I haven't been able to confirm whether or not heat gives the right output.</p>
  
  <p>I removed everything from the installer except for one of the assembly that cause this error to appear and tried compiling again.  I got the same same error.  Arrugh!</p>
  
  <p>So, my good fellows, Windows enthusiasts, and WiX users, there falls two questions:</p>
  
  <ul>
  <li>Is a typelib something that WiX can register natively?  If so, how?</li>
  <li>If not, what's the proper way of registering a typelib with a windows installer?</li>
  </ul>
  
  <p>Also, I guess as another part of this, how does Visual Studio determine how to register the typelib?  (Edit: looks the <a href="http://msdn.microsoft.com/en-us/library/ms221610%28vs.71%29.aspx" rel="noreferrer">MSDN library article on typelib registration has the names of the keys needed</a>, but I still need to figure out how to get the uuid's.  (This is from <a href="http://blogs.msdn.com/larryosterman/archive/2006/01/09/510856.aspx" rel="noreferrer">this blog post on typelib and COM registration by Larry Osterman</a>.) )  Reading a bit more, It may fall to me to register these bits manually, but I hope not...</p>
  
  <p>I evaluated the output from <code>regasm /regfile:MyDll.dll MyDll.dll</code>.  It looks like these are the same keys that wix generates for the dll.  Regasm's other mode, <code>regasm /tlb:&lt;filename&gt;</code> generates and registers the typelib for the assembly, but,</p>
  
  <blockquote>
    <p>/regfile[:FileName]  Generate a reg file with the specified name
                         instead of registering the types. This option
                         cannot be used with the /u or /tlb options</p>
  </blockquote>
  
  <p>seems the /regfile switch is incompatible with the /tlb switch.  Khaaaaaaaan!</p>
  
  <p><b>Further update:</b> It looks like you don't actually <em>need</em> to include the .tlb file.  <a href="http://chenhaoyork.wordpress.com/2009/02/15/deploy-customized-arcmap-toolbar-via-wix-2/" rel="noreferrer">According to this post on wix's typelib element</a>, an MSI can create/register this as part of the setup process.  It all comes down to configuring the WiX document to actually install it by getting the right attributes.</p>
  
  <p>I found out later that you can get the right attributes using heat on the .tlb directly!  See <a href="https://stackoverflow.com/questions/567925/typelib-generation-and-installation-with-wix">this SO question for more information</a>.</p>