Wix installer copy a folder and its content

525 views Asked by At

as for now, what I did was to painstakingly query a directory get the file names and one by one create a and as dependency of the product. I have tried i am getting errors but I am also confuse as to whether its possible or not. My directory lies in the same folder as the Wix project and it contains files and subdirectory.

I have like 200 files total and it seems like doing it one at a time is tedious with directories and subdirectory.

1

There are 1 answers

0
mcy On

Pre-note: The following are my notes from the times when I was using Wix extensively. They are a little old (from around 2017-2018) but may help you for harvesting directories.

When a project contains many files to install, it will take too much time to create file and component elements for all of them. One of the tools that is shipped with WiX (heat.exe) could create these as well. The general syntax for Heat is:

heat.exe harvestType harvestSource <harvester arguments> -o[ut] sourceFile.wxs

Heat can look at a directory, evaluate all the files in it, and create a .wxs file defining the components needed to install all those.

HarvestType

  • dir: harvest a directory
  • file: harvest a file
  • payload: harvest a bundle payload as RemotePayload
  • perf: harvest performance counters
  • project: harvest output of a VS project
  • reg: harvest a .reg file
  • website: harvest an IIS website

HarvestSource

It is the path to the directory (relative or absolute) which should not end with a backslash.

Without supplying several arguments, the output of heat is not as helpful as it should be:

  • All directory element names will be impromptu folders supplied to heat.exe, which will not be after an installation.
  • All guids are “PUT-GUID-HERE”. Heat can generate its own guids.
  • Source attributes of all File elements are set to “SourceDir\Filename”.
  • Components will not be grouped as a ComponentGroup.

To fix these issues, the following arguments should be supplied:

  • -cg: create a componentgroup with the supplied name
  • -dr : Name of the directory that will be created on the end-user's computer.
  • -gg: create GUIDs instead of fillers
  • -g1: do not use curly brackets for guids
  • -sfrag: use a single Fragment for everything
  • -srd: not to harvest the folder itself where files are
  • -var: a preprocessor variable can be used to insert in place of sourceDir.
  • -scom: suppress com element harvesting
  • -sreg: suppress registry harvesting
heat.exe dir “D:\Documents\heatf” -dr MyProgramDir -cg NewFilesGroup -gg -g1 -sfrag -srd -sreg -scom -var “var.MyDir” -out “.\heatfile2.wxs”

Now the components are grouped, each component has Guid, and installed to “MyProgramDir” folder, and file elements use the preprocessor variable supplied.

In order to use this fragment file in the main file, referencing ComponentGroup “NewFilesGroup” under a Feature is enough:

<Feature Id…>
    <ComponentGroupRef Id=”MyFilesGroup” />
</Feature>

It should be remembered that every time Heat is run on a directory and -gg flag is set, new Guids will be created for components. If a version is already installed at end users, the guids of the components should never change, as doing so will prevent Windows from accurately keeping track of them. Heat will also create new Id attributes for File and Component elements each time it is used. Note: If the binary files (dll and exe) are compiled with the flag “COM Visible”, then heat will generate the com class registrations (registry and COM element harvesting) as well in the wsx file.