In Wix, can one define a ComponentGroup and Directory at the same time?

Viewed 16325

I'm new to WiX. Very new. Is there a way to define both a ComponentGroup and a Directory at the same time?

I have a large number of files, on the order of 300 or so total, that need to be split into a number of groups, with each group having somewhere around 50 files.

Using heat.exe, I was able to create a Fragment that creates Components for each file. I would like to avoid having to re-list each and every one of these components in a separate ComponentGroup definition. I would love to be able to wrap the list of components generated by heat in a ComponentGroup definition, then simply use that ComponentGroupRef inside of a DirectoryRef structure.

I hope this clears it up. I currently must do:

<DirectoryRef Id="FilesDir">
  <Component Id="a.txt" Guid="YOUR-GUID">
    <File Id="a.txt" KeyPath="yes" Source="SourceDir\a.txt" />
  </Component>
  <Component Id="b.txt" Guid="YOUR-GUID">
    <File Id="b.txt" KeyPath="yes" Source="SourceDir\b.txt" />
  </Component>
...
  <Component Id="z.txt" Guid="YOUR-GUID">
    <File Id="z.txt" KeyPath="yes" Source="SourceDir\z.txt" />
  </Component>
</DirectoryRef>

<ComponentGroup Id="FilesGroup">
  <ComponentRef Id="a.txt">
  <ComponentRef Id="b.txt">
...
  <ComponentRef Id="z.txt">
</ComponentGroup>

I have to list every file twice. That stinks.

I'd like to be able to do:

<ComponentGroup Id="FilesGroup">
  <Component Id="a.txt" Guid="YOUR-GUID">
    <File Id="a.txt" KeyPath="yes" Source="SourceDir\a.txt" />
  </Component>
  <Component Id="b.txt" Guid="YOUR-GUID">
    <File Id="b.txt" KeyPath="yes" Source="SourceDir\b.txt" />
  </Component>
...
  <Component Id="z.txt" Guid="YOUR-GUID">
    <File Id="z.txt" KeyPath="yes" Source="SourceDir\z.txt" />
  </Component>
</ComponentGroup>

<DirectoryRef Id="FilesDir">
  <ComponentGroupRef Id="FilesGroup">
</DirectoryRef>

Is that possible? Is there some other way of making this easier that I'm just not seeing?

Update: We abandoned Wix, and therefore I'm not sure if I should mark a solution or not. If someone feels one of the answers below IS the answer to my now-rather-old question, please let me know, and I'll mark the appropriate answer as such.

3 Answers

To give a straight answer to the question: Yes you can.

<ComponentGroup Id="FilesGroup" Directory="FilesDir">
  <Component Id="a.txt" Guid="YOUR-GUID">
    <File Id="a.txt" KeyPath="yes" Source="SourceDir\a.txt" />
  </Component>
  <Component Id="b.txt" Guid="YOUR-GUID">
   <File Id="b.txt" KeyPath="yes" Source="SourceDir\b.txt" />
  </Component>
  ...
  <Component Id="z.txt" Guid="YOUR-GUID">
    <File Id="z.txt" KeyPath="yes" Source="SourceDir\z.txt" />
  </Component>
</ComponentGroup>

<!-- Later in a feature element  -->
<Feature ...>
  <Feature Id='MainProgram' Title='Program' ...>
    <ComponentGroupRef Id='FilesGroup' />
  </Feature>
</Feature>

But, it is better to let heat do this chore for you.

Related