title: WiX: How do I run heat.exe with a multi-folder setup to get multiple WXS files?
body: <p>I have a source file setup something like this: <strong>C:\Base</strong>, and in Base is <strong>FolderA</strong>, <strong>FolderB</strong>, <strong>FolderC</strong>, etc.... I want to run "heat dir" on each sub-folder in Base, so that I get one WXS file containing one ComponentGroup for each folder.</p>
  
  <p>If I run heat (from C:)</p>
  
  <pre><code>heat dir Base\FolderA -cg FolderAGroup -gg -scom -sreg -sfrag -dr -var var.SourceDir INSTALLDIR -out Components-FolderA.wxs
  </code></pre>
  
  <p>(or '<strong>heat dir FolderA ...</strong>' from C:\Base)</p>
  
  <p>(Note that I'll run heat once per FolderA, FolderB, etc... from a script. I don't expect one heat statement to take care of all folders.)</p>
  
  <pre><code>Components-FolderA.wxs looks like this: 
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"&gt;
      &lt;Fragment&gt;
          &lt;DirectoryRef Id="INSTALLDIR"&gt;
              &lt;Directory Id="dirA..." Name="FolderA"&gt;
                  &lt;Component Id="cmpF..." Guid="{GUID-HERE}"&gt;
                      &lt;File Id="filB..." KeyPath="yes" Source="$(var.SourceDir)\RandomFile.txt" /&gt;
                  &lt;/Component&gt;
              &lt;/Directory&gt;
          &lt;/DirectoryRef&gt;
      &lt;/Fragment&gt;
      &lt;Fragment&gt;
          &lt;ComponentGroup Id="FolderAGroup"&gt;
              &lt;ComponentRef Id="cmpF..." /&gt;
          &lt;/ComponentGroup&gt;
      &lt;/Fragment&gt;
  &lt;/Wix&gt;
  </code></pre>
  
  <p>The problem with this is that <strong>Source="$(var.SourceDir)\RandomFile.txt</strong> uses whatever I specify as <strong>SourceDir</strong>. So if I designate C:\Base as <strong>SourceDir</strong>, the file RandomFile.txt can't be found because it's looking for C:\Base\RandomFile.txt, not C:\Base\FolderA\RandomFile.txt. I can't specify C:\Base\FolderA as <strong>SourceDir</strong> because FolderB, FolderC, etc... will be wrong. <strong>So how do I tell heat to insert 'FolderA\' in between '$(var.SourceDir)\' and 'RandomFile.txt'</strong>?</p>
  
  <p>I have looked at <a href="https://stackoverflow.com/questions/17108287/harvesting-multiple-directories-in-wix/">Harvesting multiple directories in WiX</a>, but the first answer is too much manual work (we're lookong for almost complete automation) and the second answer puts everything in one file under one ComponentGroup, which would be a maintenance nightmare as we have thousands of files and dozens of folders and sub-folders to be installed.</p>