Candle (part 1)
The core of the WiX toolset primarily consists of a compiler and a linker. The compiler is called candle and the linker is called light (here's an explanation of how these names came about). The functionality provided in each of these tools seems to be a source of constant debate by many users of WiX. I've even been confused about whether a certain operation was performed in the compiler or linker from time-to-time. For this post, I'd like to talk about candle. Parsing The guts of candle are basically implemented in two classes: preprocessor.cs (the preprocessor) and compiler.cs (the compiler). Let's leave a discussion of preprocessor.cs for another time. The class Microsoft.Tools.WindowsInstallerXml.Compiler in compiler.cs is nothing more than a simple recursive-decent parser. Although the formal definition seems to make this seem complicated, it really isn't. An example will probably be the easiest way to illustrate how simple the parsing code is. Here's the contents of a simple WiX source file (let's call it example.wxs):
The compiler will begin parsing this file by looking at the element first. This is done by calling ParseWixElement. Inside the method ParseWixElement (which can be found in compiler.cs), there is a foreach loop for processing each of the child elements under a Wix element. In fact, here's a simplied version of what that code looks like: ///
/// Parses a Wix element.
/// Element to parse.
private void ParseWixElement(XmlNode node)
foreach (XmlNode child in node.ChildNodes)
if (XmlNodeType.Element == child.NodeType)
} Since the first child element of the element is a element, the compiler will then call ParseFragmentElement. This method would then call ParsePropertyElement. There is a Parse*Element method for each of the elements supported by WiX in its source files. Each element roughly corresponds to a particular table in an MSI file. So, in the example above, we'd be creating a single row in the Property table by writing a element. To be continued...