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 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
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
sfrag option tells it to suppress wrapping individual directories and components in a Fragment element. The
g1 options tell it to generate GUIDs for the components, but without the curly braces.
Component elements can be copied from within the
DirectoryRef element in
out.wxs to the target wxs. Similarly, the list of
ComponentRef elements in the
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 )