WiX Tutorial (2/7)
Properties are the variables used to store data needed during an installation. There are several built-in properties and more can be declared by the developer in his WiX source files.
Some of the elements defined in a WiX source file can be referenced from other parts of
the source file by using the corresponding reference element. For instance in our
we used the
ComponentRef element to reference a
Component element. Other examples
References are particularly useful when used in conjunction with fragments. The
element is a container in which other elements can be defined. These elements can then be referenced using the
corresponding Ref element. This technique can be used to better organize large installers by
splitting the source into several files for instance.
Looking at the WiX schema  you can see that the
<Wix> element in a WiX source file can
contain an optional
<Product> element followed by any number of
This means that you can have files containing only fragments whose contents can then be referenced in other Wix source files.
This should come as no surprise as the WiX build process follows the same principles as the compilation and linking stage of
some programming languages like C. Note that there is no concept of "header files" as in C or C++ and that you don't need to include
a file to use its elements, the WiX toolchain will look for the referenced elements in all the
that are passed to
We have rewritten our previous example, SingleFileInstallation1, to use a
<Fragment> element that we have
out in a separate file. Both files are reproduced below.
The full example is available from our Codeplex repository at WiX/Basics/Fragments1.
<?xml version="1.0" encoding="UTF-8"?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <Product Id="0C6F4EF7-7B03-49FA-9FF6-BAAFCFCBCF4A" Name="Fragments1" Language="1033" Version="22.214.171.124" Manufacturer="Needful Software" UpgradeCode="2B7E0978-680A-43A5-A0D0-98CF921EE4E5"> <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" /> <MediaTemplate EmbedCab="yes" /> <Feature Id="MainProduct" Title="Fragments 1" Level="1"> <ComponentRef Id="HelloWorldComponent" /> </Feature> </Product> </Wix>
<?xml version="1.0" encoding="UTF-8"?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <Fragment> <Directory Id="TARGETDIR" Name="SourceDir"> <Directory Id="ProgramFilesFolder"> <Directory Id="NeedfulSoftwareDir" Name="Needful Software"> <Directory Id="Fragments1Dir" Name="Fragments 1"> <Component Id="HelloWorldComponent" Guid="118B788F-0D94-4F07-B845-6AB70224C3FB"> <File Id="HelloWorldFile" Source="HelloWorld.txt" KeyPath="yes" /> </Component> </Directory> </Directory> </Directory> </Directory> </Fragment> </Wix>
We now have two source files so we need to pass them both to
shown below. We also have to use the
-o option with
light.exe to specify
the name of the output file.
C:\WiX\Examples\Fragments1>candle.exe Fragments1.wxs Files.wxs Windows Installer XML Toolset Compiler version 3.8.1128.0 Copyright (c) Outercurve Foundation. All rights reserved. Fragments1.wxs Files.wxs C:\WiX\Examples\Fragments1>light.exe Fragments1.wixobj Files.wixobj -o Fragments.msi Windows Installer XML Toolset Linker version 3.8.1128.0 Copyright (c) Outercurve Foundation. All rights reserved. C:\WiX\Examples\Fragments1>
blog comments powered by Disqus