title: Decoupling Wix Component from ComponentGroup
body: <p>I'm trying to generate Wix source from a custom Visual Studio extension. As such, I'd like to be able to (somehow) just add one file (plus project reference) to the Wix Project, and have the new DLLs added in to the Product.</p>
  
  <p>As an example:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Product Id="*" Name="blah" Version="..." Manufacturer="foo" UpgradeCode="..."&gt;
      &lt;Package InstallerVersion="200" ... /&gt;
  
      &lt;MajorUpgrade DowngradeErrorMessage="..." /&gt;
      &lt;MediaTemplate EmbedCab="yes" /&gt;
  
          &lt;Feature Id="ProductFeature" Title="blah" Level="1"&gt;
              &lt;ComponentGroupRef Id="ProductComponents" /&gt;
          &lt;/Feature&gt;
          &lt;!-- Custom actions, Directories, etc .... --&gt;
  &lt;/Product&gt;
  </code></pre>
  
  <p>Then in separate files (which I want to be generated), I have some Fragments:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Fragment&gt;
      &lt;DirectoryRef Id="MYINSTALLDIR"&gt;
         &lt;Component Id="CMP_FILE1" Guid="..."&gt;
           &lt;File Id="FILE1" Source="file1.dll" Assembly=".net" KeyPath="yes" /&gt;
         &lt;/Component&gt;
     &lt;/DirectoryRef&gt;
  &lt;/Fragment&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Fragment&gt;
      &lt;DirectoryRef Id="MYINSTALLDIR"&gt;
         &lt;Component Id="CMP_FILE2" Guid="..."&gt;
           &lt;File Id="FILE2" Source="file2.dll" Assembly=".net" KeyPath="yes" /&gt;
         &lt;/Component&gt;
     &lt;/DirectoryRef&gt;
  &lt;/Fragment&gt;
  </code></pre>
  
  <p>So far so good. The problem is that I need to tie those together with something like:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Fragment&gt;
    &lt;ComponentGroup Id="ProductComponents"&gt;
      &lt;ComponentRef Id="CMP_FILE1" /&gt;
      &lt;ComponentRef Id="CMP_FILE2" /&gt;
    &lt;/ComponentGroup&gt;
  &lt;/Fragment&gt;
  </code></pre>
  
  <p>That works, but I don't want to do that, because it requires editing of the <code>ComponentGroup</code> when I want to add the next file. </p>
  
  <p>So I want to try to localise the information into my added file. I can live with it always being part of the same Feature.</p>
  
  <p>I tried adding the <code>Feature</code> attribute to <code>Component</code> element:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Fragment&gt;
      &lt;DirectoryRef Id="MYINSTALLDIR"&gt;
         &lt;Component Id="CMP_FILE1" Guid="..." Feature="ProductFeature"&gt;
           &lt;File Id="FILE1" Source="file1.dll" Assembly=".net" KeyPath="yes" /&gt;
         &lt;/Component&gt;
     &lt;/DirectoryRef&gt;
  &lt;/Fragment&gt;
  </code></pre>
  
  <p>but that didn't seem to add the <code>Component</code> to the parent feature (empty Media table warning from Wix on build, and Orca confirmed it).</p>
  
  <p>I also tried adding the <code>ComponentGroup</code> to each generated file, but of course I can't duplicate <code>Id</code> attributes, and unique <code>Id</code> just pushes the coupling problem up into <code>Feature</code>...</p>
  
  <p>Is there a way to add a <code>Component</code> without editing the <code>ComponentGroup</code>?</p>