title: Using a variable for ComponentGroup/@Directory in WiX
body: <p>I have a WiX library project which contains several componentgroups similar to this</p>
  
  <pre><code>&lt;ComponentGroup Id="CG_Group1" Directory="INSTALLFOLDER" Source="$(var.FilesLocation)"&gt;
    &lt;Component Id="C_Group1_file1.file"&gt;
      &lt;File Name="Group1_file1.file" Id="FI_Group1_file1.file" /&gt;
    &lt;/Component&gt;
  &lt;/ComponentGroup&gt;
  </code></pre>
  
  <p>This library is shared by multiple WiX installer projects, and now i want the value of the <code>Directory</code> attribute of the <code>ComponentGroup</code> to be decided by the installer project referencing it.
  What I have done in similar situations is to define WiX-variables in the installer projects like this</p>
  
  <pre><code>&lt;WixVariable Id="FOLDERIDTOUSE" Value="SOMEID"/&gt;
  </code></pre>
  
  <p>and referenced the variable from the wix library with</p>
  
  <pre><code>!(wix.FOLDERIDTOUSE)
  </code></pre>
  
  <p>However when doing this for the <code>Directory</code> attribute of the <code>ComponentGroup</code> I get an error</p>
  
  <blockquote>
    <p>The ComponentGroup/@Directory attribute's value, '!(wix.FOLDERIDTOUSE)', is not a legal identifier.  Identifiers may contain ASCII characters A-Z, a-z, digits, underscores (_), or periods (.).  Every identifier must begin with either a letter or an underscore.</p>
  </blockquote>
  
  <p>Doesn't the <code>CompontentGroup/@Directory</code> support injection through wix-variables?</p>
  
  <p>Is there another way to achieve what I'm trying to do?</p>
  
  <p>Edit:
  This is what I'm trying to do:</p>
  
  <p>In wix library:</p>
  
  <pre><code>&lt;ComponentGroup Id="CG_Group1" Directory="!(wix.FOLDERIDTOUSE)" Source="$(var.FilesLocation)"&gt;
    &lt;Component Id="C_Group1_file1.file"&gt;
      &lt;File Name="Group1_file1.file" Id="FI_Group1_file1.file" /&gt;
    &lt;/Component&gt;
  &lt;/ComponentGroup&gt;
  </code></pre>
  
  <p>In Installer Project(s):</p>
  
  <pre><code>&lt;Directory Id="FOLDERSPECIFICTOTHISPROJECT" Name="MyFolder/&gt;
  &lt;WixVariable Id="FOLDERIDTOUSE" Value="FOLDERSPECIFICTOTHISPROJECT"/&gt;
  </code></pre>