DAVEWASLIN
DAVEWASLIN

Reputation: 159

How can I add ComponentGroupRefs to a feature automatically after generating fragments with heat.exe

I have a requirement to dynamically create an installer using for a list of files contained in a text file.

The file list contains individual files from many different directories, and is prone to change on a fairly regular basis. I am attempting to create an installer that will not need to be updated each time a new version of the file list is created.

So far I am calling heat.exe from the command line inside a cmd script, where I use a for loop to iterate through the file list, running a heat command against each file to create a fragment of the component.

FOR /F "delims=;"  %%a IN (FileList.txt) DO (heat.exe file "%%a" -cg ComponentGroupName -gg -g1 -sfrag -dr DirectoryName %%~da -out "%~dp0%%~na.wxs")

Obviously this bit of code will give each ComponentGroup the same name, which poses an issue, but I can solve that by using the name of the file inside the component group name when I get around to it.

The bit I am struggling with is how to add the name of the component group to a feature element inside my Project.wsx file.

I have read through the Wix Toolset Documentation Manual and the relevant sections in the book WiX 3.6: A Developer's Guide to Windows Installer XML and cannot find out how to do this.

I appreciate that I could use some form of text replacement to do this, but I was hoping there was something built into the Wix Toolset as I cant be the first person with the need to dynamically create heat generated components.

Upvotes: 1

Views: 995

Answers (1)

DAVEWASLIN
DAVEWASLIN

Reputation: 159

Ive come up with an acceptable solution to my issue. What im doing is running a cmd file to generate the heat components. Each of these components is stored in its own componentGroup, identified by the id "ComponentGroup" + the iterative counter of the file in the list of files.

After the heat components have been generated, I then create a further ComponenGroup in a separate wxs file, which contains ComponentGroupRefs to each of the ComponentGroups created by heat.

As this ComponentGroup is created from the cmd file and I know the Id of, I am able to reference it in my feature.

    @echo off
setlocal enabledelayedexpansion

set /a count = 0
FOR /F "delims=;" %%a IN (FileList.txt) DO (
set /a count=count+1
heat.exe file "%%a" -cg "ComponentGroup!count!" -gg -g1 -sfrag -dr NotSureWhatGoesHereYet %%~da -out "%~dp0%%~na.wxs" 
)

(
echo ^<?xml version="1.0" encoding="utf-8"?^>
echo ^<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"^>
echo      ^<Fragment^>
echo          ^<ComponentGroup Id="ComponentGroup"^>
) > test.wxs

FOR /L %%i IN (1,1,%count%) DO (
  echo              ^<ComponentGroupRef Id="ComponentGroup%%i" /^> >> Components.wxs
)

(
echo          ^</ComponentGroup^>
echo     ^</Fragment^>
echo ^</Wix^> 
) >> Components.wxs

Thanks for the responses guys. @TomBlodget I took inspiration from your first answer. Thanks for your time

Upvotes: 2

Related Questions