title: How to write and use a retargetable merge module in wix
body: <p>I would like to write and use a minimal retargetable merge module. It should contain 3 files</p>
  
  <pre><code>PS C:\Users\mto\sandbox\wixme3&gt; Get-ChildItem files
  
  
  Directory: C:\Users\mto\sandbox\wixme3\files
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  -----        16.02.2015     18:08          0 a
  -----        16.02.2015     18:08          0 b
  -----        16.02.2015     18:08          0 c
  </code></pre>
  
  <p>I have the following merge module:</p>
  
  <pre><code>PS C:\Users\mto\sandbox\wixme3&gt; Get-Content .\MergeModule.wxs
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"&gt;
      &lt;Module Id="a_merge_module" Language="1033" Version="1.0.0.0"&gt;
          &lt;Package Id="92b702f4-8687-4bbf-b8c2-24c42be52730" Manufacturer="Me" Description="a merge module" InstallerVersion="300" Platform="x86"&gt;&lt;/Package&gt;
          &lt;ComponentGroupRef Id="allTheFilesINeed"/&gt;
          &lt;Directory Id='TARGETDIR' Name='SourceDir'&gt;
          &lt;/Directory&gt;
      &lt;/Module&gt;
  &lt;/Wix&gt;
  </code></pre>
  
  <p>I use it like this:</p>
  
  <pre><code>PS C:\Users\mto\sandbox\wixme3&gt; Get-Content .\Product.wxs
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"&gt;
      &lt;Product Name='TestRelocatableMergeModule' Id='d5c54f50-52df-11e4-916c-0800200c9a66' UpgradeCode='e07a1cf0-52df-11e4-916c-0800200c9a66'
           Language='1033' Codepage='1252' Version='1.0.0' Manufacturer='Me'&gt;
          &lt;Package Id='*' Keywords='Installer' Description="test merge module"
            Comments='Test Installer' Manufacturer='Acme Ltd.'
            InstallerVersion='301' Languages='1033' Compressed='yes' SummaryCodepage='1252' Platform='x86'/&gt;
  
          &lt;Media Id="1" Cabinet="product.cab" EmbedCab="yes" /&gt;
  
          &lt;Directory Id='TARGETDIR' Name='SourceDir'&gt;
              &lt;Directory Id="SOMETHING" Name="my_special_folder"&gt;
              &lt;/Directory&gt;
          &lt;/Directory&gt;
          &lt;DirectoryRef Id="SOMETHING"&gt;
              &lt;Merge Id="merge" Language="1033" SourceFile="merge_module.msm" DiskId="1" /&gt;
          &lt;/DirectoryRef&gt;
          &lt;Feature Id="Msm" Title="Msm" Level="1"&gt;
              &lt;MergeRef Id="merge" /&gt;
          &lt;/Feature&gt;
      &lt;/Product&gt;
  &lt;/Wix&gt;
  </code></pre>
  
  <p>and stitch it together like this:</p>
  
  <pre><code>PS C:\Users\mto\sandbox\wixme3&gt; Get-Content .\makeInstaller.cmd
  del *.wixobj
  del allTheFilesINeed.wixobj
  del allTheFilesINeed.wxs
  del *.msi
  del *.msm
  heat.exe dir "files" -cg allTheFilesINeed -var var.BUILDFOLDER -gg -g1 -srd -sfrag -o allTheFilesINeed.wxs
  candle.exe -dBUILDFOLDER="files" allTheFilesINeed.wxs MergeModule.wxs -v
  candle.exe Product.wxs
  light.exe -dBUILDFOLDER="files" allTheFilesINeed.wixobj MergeModule.wixobj -o merge_module.msm
  light.exe Product.wixobj -o product.msi
  </code></pre>
  
  <p>This does not work as expected. The folder in <code>Product.wxs</code> is ignored and the files goes directly under <code>C:\</code>. I have read that I need to use a retargetable merge module. The merge module should then use a configuration setting to decide where to put it's  files. This configuration should be set in the product that uses the merge module. I have not been able to find an example of how to do this. Can anyone point me in the right direction?</p>