How WiX Toolset Compiles MSI from XML Source Files
The WiX (Windows Installer XML) Toolset creates standard Windows
Installer (.msi) packages by transforming declarative XML
source code into relational database tables required by the Windows
Installer engine. This compilation workflow processes human-readable
markup, resolves file dependencies and references, generates
intermediate symbol representations, and finally packages binary
payloads into a fully structured MSI database.
1. Writing the Declarative XML
(.wxs)
The process begins with WiX source files (.wxs) and
optional include files (.wxi). Developers declare the
installer’s structure using XML elements that correspond to Windows
Installer concepts: * Product and Package: Define
metadata such as product names, upgrade codes, and manufacturer details.
* Directory Structure: Define target installation
paths. * Components and Files: Specify the individual
files, registry keys, and shortcuts to install. *
Features: Group components into selectable installation
items. * Sequences and Actions: Specify standard or
custom actions to execute during setup.
2. Preprocessing
Before compilation, the WiX engine runs a preprocessor over the XML
files. The preprocessor evaluates: * Environment variables and defined
constants ($(var.VariableName)). * Conditional compilation
statements (<?ifdef ?>, <?if ?>).
* File inclusion directives (<?include ?>).
This step produces a fully resolved XML tree ready for compilation.
3. Compilation
The compiler parses the preprocessed XML source against the WiX XML schema to ensure structural validity.
- In WiX v3, this step is executed using
candle.exe. - In WiX v4 and v5, this is integrated into the
unified
wix buildcommand.
The compiler converts high-level XML abstractions into intermediate
object files (.wixobj). These intermediate files contain
symbols, relational rows, and references matching standard Windows
Installer database tables (such as Directory,
Component, File, Feature, and
Registry).
4. Linking and Symbol Resolution
The linker combines multiple .wixobj files and
precompiled libraries (.wixlib): * Symbol
Resolution: Connects referenced identifiers (e.g., a component
referencing a target directory ID) across different source files. *
Database Generation: Creates the relational tables and
populates standard sequence tables (InstallExecuteSequence,
InstallUISequence) which govern the installation flow. * In
WiX v3, this is handled by light.exe.
5. File Binding and Cabinet Creation
Once the database schema is assembled, the binder handles actual file
assets: * Retrieves physical binary files from the local filesystem
based on paths declared in the source. * Calculates file hashes,
versions, and sizes to populate the File table. *
Compresses these payloads into internal or external Cabinet
(.cab) files. * Streams internal CAB files and necessary
icons/transforms directly into the streams table of the MSI
database.
6. Validation (ICE Checks)
By default, the compilation pipeline executes Internal Consistency
Evaluators (ICE). These are validation rules developed by Microsoft that
check the generated database for standard compliance, missing foreign
keys, circular directory paths, and component rules. Once validation
passes, the resulting .msi file is ready for
deployment.