If you are creating a new WiX Installer, files have to be added into installer that will be installed on user system. There are various way to add those files into WiX. If your project is evolving and you need to deploy installers constantly, it’s better to use WiX file harvester. The idea is that it takes all files needed for installer automatically, and packs it to WiX file that can be later included in WiX installer project.
We are going to write installer for my simple project, ConfigurationUtility. This tutorial is not for complete beginners, so you should have little experience with WiX.
- Create new WiXProject(in Visual Studio 2010 or 2012, doesn’t matter – make sure you install >=Wix3.6 before)
- In your WiXProject, add reference to ConfigurationUtility project. This step is needed to have make installer little less error-prone(avoids some hardcoding).
- Go to your WiXProject and add pre-build events(right click on project -> properties -> Build Events), and add this:
heat dir "$(SolutionDir)ConfigurationUtility\bin\$(Configuration)" -dr ConfigurationUtilityDir -cg ConfigurationUtilityComponents -gg -g1 -sf -srd -var "var.ConfigurationUtility.TargetDir" -out "$(SolutionDir)WiXProject\ConfigurationUtilityHeat.wxs"
Note; If you are wondering about flags, go check out heat documentation.
- ConfigurationUtilityHeat.wxs will be generated once you build your WiXProject. Add ConfigurationUtilityHeat.wxs into your WiXProject(“Add existing item” in VS).
- Now it’s time to edit your Product.wxs and pull in the “ConfigurationUtilityHeat.wxs” file. Open Product.wxs, and add:
<!-- Add ComponentGroupRef to existing Feature, or create new one --> <!-- Notice the IDs & what we used in heat --> <Feature Id="ProductFeature" Title="Main product" Level="1"> <ComponentGroupRef Id="ConfigurationUtilityComponents"/> </Feature> <Fragment> <Directory Id="INSTALLDIR" Name="SourceDir"> <Directory Id="ProgramFilesFolder"> <Directory Id="ConfigurationUtilityDir" Name="ConfigurationUtility" /> </Directory> </Directory> </Fragment>
And.. that’s it! The idea of harvesting is that every time we build our WiXProject, it will harvest ALL the files in concrete folder, and spit out ConfigurationUtilityHeat.wxs file, that can later be included. WiX does also offer project harvesting, which sounds very cool – until you find out that it doesn’t harvest the references of a project. That’s basically useless in my opinion. I do believe they are working for a fix, and it’s pretty complicated problem.