Adding lots of source files to a WiX installer script

Now that Visual Studio has dropped support for creating installers, I have taken to studying the WiX Toolset quite earnestly. Manually editing the WiX script is all right as long you have a handful of files. A particular installer I am working on has over nine hundred. I need to bundle the Node.js executable along with all the node_modules.

A quick look at the WiX documentation revealed the heat tool, that when executed thus produces a script file with elements that we can copy and paste into your wxs

"c:\Program Files (x86)\WiX Toolset v3.6\bin\heat.exe" dir . -o out.wxs -cg MyComponentGroup -sfrag -gg -g1

The dir option followed by a . tells heat to gather the directory structure (source file) information from the current folder and its children. The cg option tells it to create a ComponentGroup with an id of MyComponentGroup. The sfrag option tells it to suppress wrapping individual directories and components in a Fragment element. The gg and g1 options tell it to generate GUIDs for the components, but without the curly braces.

The Component elements can be copied from within the TARGETDIR DirectoryRef element in out.wxs to the target wxs. Similarly, the list of ComponentRef elements in the MyComponentGroup ComponentGroup can be copied into the Feature element of the target wxs.

A Sample Wix Installer Script

The following installer script can serve as a starting point for your installer. It does several things

  • Install files and folders to User’s Local AppData folder
  • Add shortcut to node.exe in the Start menu and on the Desktop
  • Add a shortcut to uninstall the app in the Start menu
  • Uninstall older version when upgrading
  • Allow killing node.exe during uninstall if it is in execution
  • Customizing the icons and bitmaps that appear in the installer UI

Remember to replace UpgradeCodeGuidHere with a valid GUID. GUIDs can be generated by executing guidgen.exe from Visual Studio’s Developer Command Prompt. Choose the registry format and remove the braces. There are also quite a few online GUID generators.

Compiling and linking

To compile the above script using the WiX compiler, execute

candle.exe demo.wxs -ext WixUtilExtension

To link the object file produced by the compiler and create an msi, execute

light.exe -out demo.msi demo.wixobj -ext WixUIExtension -ext WixUtilExtension

You can put both steps in a batch file

set WIX_BIN=c:\Program Files (x86)\WiX Toolset v3.6\bin\
echo Wix Toolset Bin Path: %WIX_BIN%
"%WIX_BIN%candle.exe" demo.wxs -ext WixUtilExtension
if exist demo.wixobj (
  "%WIX_BIN%light.exe" -out demo.msi demo.wixobj -ext WixUIExtension -ext WixUtilExtension

One thought on “Adding lots of source files to a WiX installer script

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s