Windows Installer XML (WiX) Help

Transcription

Windows Installer XML (WiX) v3.0 HelpThis documentation contains information about the Windows InstallerXML (WiX) toolset. See the following topics for more detailed information:IntroductionAbout WiXUsing WiX on the Command LineUsing WiX in Visual StudioUsing WiX with MSBuildUsing WiX with NAntHow To GuidesWiX Schema ReferenceAdvanced WiX TopicsDeveloping for WiXAdditional Resources

Introduction to Windows Installer XML(WiX) toolsetWhat is WiX?WiX is a set of tools and specifications that allow you to easily createWindows Installer database files. The WiX tools model the traditionalcompile and link model used to create executables from source code. ForWiX, source code is written in XML files. These files are validated againsta schema, wix.xsd, then processed by a preprocessor, compiler, andlinker to create the desired result. WiX has been designed to allow for theeasy creation of multiple Windows Installer databases from a small set ofsource files. You can use WiX both on the command line and in theVisual Studio development environment.

Additional ResourcesGetting Started Learning WiX

About WiXWindows Installer XML, or WiX, provides a schema that describes aWindows Installer database (MSI or MSM), as well as tools to convert theXML description files into a usable database. The WiX tools model thetraditional compile and link model used to create executables fromsource code. This section provides an introduction on the tools andconcepts as well as an overview of the file types in WiX.Note: This document assumes you have a working knowledge of theWindows Installer database format.File TypesTools and Concepts

File TypesThere are many file types in WiX that are generated from different tools inthe toolset. At the highest level, all input files and intermediate files forWiX are XML files. The output is in the form of standard WindowsInstaller database files.Source files (.wxs and .wxi) are compiled, producing object files (.wixobj).These objects files are then consumed by the linker, which producesWindows Installer database files (.msi or .msm). This is analogous to theC model of compiling source code to object files, then linking toproduce executables.

List of file typesThe following list describes the supported file types in WiX:Extension TypeDescription.wxiWiXA .wxi file is analogous to .h files for C . TheInclude File root element of this file is Include . Everythingunder the root element will be inserted inlinewhen this file is included in another source orinclude file.wxlWiXA .wxl file contains a set of strings used forLocalization localizing a product into a specified culture. TheFileroot element of this file is WixLocalization .The culture is specified by setting the Cultureattribute on the WixLocalization element.wxsWiX Source A .wxs file is analogous to a .cpp file for C .FileThe Root element of this file is Wix .wixobjWiX Object A .wixobj file is created by the compiler for eachFilesource file compiled. The .wixobj file containsone or more sections that, in turn, containsymbols and references to other symbols.wixoutWiX XML A .wixout file is created by the linker whichOutput File represents the result of linking a set of objectfiles. The .wixout is an XML representation ofthe final output.wixlibWiX Library A .wixlib file is a library of setup functionalityFilethat can be easily shared across different WiXbased packages by including it when linking thesetup package.

.wixpdbWiX Debug A .wixpdb file is created by the linker for eachFilefinal output. It contains the debugginginformation.wixmspWiX XMLPatch FileA .wixmsp file is the XML output generated bylinking object files in a patch build.wixmstWiXTransformFileA .wixmst file is an XML representation of thedifference between a pair of final outputs orXML outputs.msiWindowsInstallerInstallationPackageAn installation package file (.msi) is the basicunit of installation for the Windows Installer. Formore information on .msi files, see the WindowsInstaller documentation.msmWindowsInstallerMergeModuleA merge module file (.msm) is used to sharesetup logic across different .msi packages. Amerge module can be created by onedevelopment team, then merged into anotherdevelopment team's .msi package. For moreinformation on .msm files, see the WindowsInstaller documentation.mstWindowsInstallerTransformA transform file (.mst) is used to apply changesto an .msi file. For more information on .mstfiles, see the Windows Installer essA patch creation properties file (.pcp) is used asan input to the patch building tools provided inthe Windows Installer SDK. For moreinformation on .pcp files, see the WindowsInstaller documentation.

Additional InformationWindows Installer XML Files - .wxs & .wixobjA .wxs file is used by all source files in the Windows Installer XMLsystem. These .wxs files are analogous to .cpp files for C or .cs filesfor C#. The .wxs files are preprocessed and then compiled into WiXobject files, which use the extension .wixobj. When all of the source fileshave been compiled into object files, the linker is used to collect theobject files together and create a Windows Installer database. Moredetails on the compiler and linker are provided later in this topic.Structure of .wxs filesAll .wxs files are well-formed XML documents that contain a single rootelement named Wix/ . The rest of the source file may or may notadhere to the WiX schema before preprocessing. However, after beingpreprocessed all source files must conform to the WiX schema or theywill fail to compile.The root Wix element can contain at most one of the followingelements as children: Product , Module , and Patch . However,there can be an unbounded number Fragment elements as children ofthe root Wix element. When a source file is compiled into an object file,each instance of these elements creates a new section in the object file.Therefore, these three elements are often referred to as sectionelements.It is important to note, that there can be only one Product or Module or Patch section element per source file because they are compiledinto special sections called entry sections. Entry sections are used asstarting points in the linking process. Sections, entry sections, and theentire linking process are described in greater detail later in thisdocument.The children of the section elements define the contents of the WindowsInstaller database. You’ll recognize Property elements that map toentries in the Property table and a hierarchy of Directory elements that

build up the Directory table. Most elements contain an “Id” attribute thatwill act as the primary key for the resulting row in the Windows Installerdatabase. In most cases, the “Id” attribute also defines a symbol whenthe source file is compiled into an object file.Symbols and referencesEvery symbol in an object file is composed of the element name plus theunique identifier from the “Id” attribute. Symbols are important becausethey can be referenced by other sections from any source file. Forexample, a Directory structure can be defined in a Fragment in onesource file and a Component can be defined under a different sourcefile’s Fragment . By making the DirectoryRef element a parent of the Component an explicit reference is created that references the symboldefined by a Directory in the first source file. The linker is thenresponsible for stitching the symbol and the reference together in a singleWindows Installer database. In some cases, implicit references aregenerated by the compiler while processing a source file. These implicitreferences behave identically to explicit references.In addition to the simple references described above, WiX supportsspecific complex references. Complex references are used in caseswhere the linker must generate extra information to link the symbol andreference together. The perfect example of a complex reference is in theWindows Installer’s Feature/Component relationship. When a Component is referenced explicitly by a Feature through a ComponentRef element, the linker must take the Feature ’s symboland the Component ’s symbol and add an entry to theFeatureComponents table.This Feature/Component relationship is even more complex becausecertain elements in a Component , for example Shortcut , havereferences back to the primary Feature associated with the Component.These references from a child element of a Component are calledreverse references or sometimes feature backlinks. Processing complexreferences and reverse references is probably the most difficult work thelinker has to do.Structure of the .wixobj file

A .wixobj file is created by the compiler for each source file compiled. The.wixobj file is an XML document that follows the objects.xsd schemadefined in the WiX project. As stated above the .wixobj file contains oneor more sections that, in turn, contain symbols and references to othersymbols.While the symbols and references are arguably the most importantpieces of data in the .wixobj file, they are rarely the bulk of theinformation. Instead, most .wixobj files are composed of table , row and field elements that provide the raw data to be placed in theWindows Installer database. In many cases, the linker will not onlyprocess the symbols and references but also use and update the rawdata from the .wixobj file. It is interesting to note that the object fileschema, objects.xsd, uses camel casing where the source file schema,wix.xsd, uses Pascal casing. This was a conscious choice to indicate thatthe object files are not intended to be edited by the user. In fact, allschemas that define data to be processed only by the WiX tools usecamel casing.

Tools and ConceptsThis section explores the concepts of the preprocessor, compiler, andlinker. In addition, it provides a complete list of tools that WiX offers.List of toolsPreprocessorCompiler (Candle)Linker (Light)Library Tool (Lit)Harvester (Heat)Decompiler (Dark)WixCop

DiagramBelow is a diagram showing the relationship of all of the WiX tools andthe output that they generate.

List of ToolsNameDescriptionCandle Preprocesses and compiles WiX source files into object files(.wixobj).LightLinks and binds one or more .wixobj files and creates aWindows Installer database (.msi or .msm). When necessary,Light will also create cabinets and embed streams into theWindows Installer database it creates.LitCombines multiple .wixobj files into libraries that can beconsumed by Light.DarkConverts a Windows Installer database into a set of WiX sourcefiles.HeatGenerates WiX authoring from various input formats.MeltConverts an .msm into a component group in a WiX source file.TorchPerforms a diff to generate a transform (.wixmst or .mst) forXML outputs (.wixout or .wixpdb) or .msi files.Smoke Runs validation checks on .msi or .msm files.PyroTakes an XML output patch file (.wixmsp) and one or more XMLtransform files (.wixmst) and produces an .msp file.WixCop Enforces standards on WiX source files. WixCop can also beused to assist in converting a set of WiX source files createdusing an older version of WiX to the latest version of WiX.

Response filesAll WiX command-line tools support response files, which are text filesthat contain command-line switches and arguments. Anything you canput on a WiX tool command line can instead go into a response file.Response files are useful when you have command lines that are toolong for your command shell. For example, you might want to generate aresponse file that contains command-line switches and the files that youwant to compile with candle.exe:-nologo -wx1.wxs2.wxs 3.wxsand issue a command like:candle @listOfFiles.txtSpecify a response file with the @ character, followed immediately by thepathname of the response file, with no whitespace in-between. Responsefiles can appear at the beginning, in the middle, or at the end ofcommand line arguments.

PreprocessorIntroductionOften you will need to add different pieces of your setup during build timedepending on many factors such as the SKU being built. This is done byusing conditional statements that will filter the xml before it is sent to theWiX compiler (candle). If the statement evaluates to true, the block of xmlwill be sent to candle. If the statement evaluates to false, candle willnever see that section of xml.The conditional statements are Boolean expressions based onenvironment variables, variables defined in the xml, literal values, andmore.ExampleLet’s start with an example. Say you want to include a file if you’rebuilding the “Enterprise SKU.” Your build uses an environment variable%MySku% Enterprise to specify this sku.When you build the enterprise sku, this file will be included in the xmlpassed on to candle. When you build a different sku, the xml fromEnterpriseFeature.wxs will be ignored. ?if (env.MySku) Enterprise ? ?include EnterpriseFeature.wxs ? ?endif ?

Include Files ?include? As shown in the example above, files can be included by using theinclude tag. The filename referenced in the tag will be processed as if itwere part of this file.The root element of the include file must be Include . There are noother requirements beyond the expected wix schema. For example, Include Feature Id 'MyFeature' Title 'My 1st Feature' Level '1' ComponentRef Id 'MyComponent' / /Feature /Include

VariablesAny variable can be tested for its value or simply its existence. Customvariables can also be defined in your xml.Three types of variables are supported: (env. NtPostBld)Gets the environment variable % NtPostBld% (sys.CURRENTDIR)Gets the system variable for the current directory (var.A)Gets the variable A that was defined in this xmlThe preprocessor evaluates variables throughout the entire document,including in ?if? expressions and attribute values.Environment VariablesAny environment variable can be referenced with the syntax (env.VarName). For example, if you want to retrieve the environmentvariable % BuildArch%, you would use (env. BuildArch). Environmentvariable names are case-insensitive.System VariablesWiX has some built-in variables. They are referenced with the syntax (sys.VARNAME) and are always in upper case.CURRENTDIR - the current directory where the build process is runningSOURCEFILEPATH – the full path to the file being processedSOURCEFILEDIR – the directory containing the file being processedPLATFORM – the platform (Intel, x64, Intel64) this package is compiledfor (set by the Package element's Platform attribute)NOTE: All built-in directory variables are “\” terminated.

Custom variables ? define ? If you want to define custom variables, you can use the ?define? statement. You can also define variables on the command line usingcandle.exe using the -d switch. Later, the variables are referred to in the ?if? statements with the syntax (var.VarName). Variable names arecase-sensitive.How to define the existence of a variable: ?define MyVariable ? How to define the value of a variable (note: quotes are required if thevalue or the expansion of other variables in the value contain spaces): ?define MyVariable “Hello World” ? ?define MyVariable “ (var.otherVariableContainingSpaces)” ? The right side of the definition can also refer to another variable: ?define MyVariable (var.BuildPath)\x86\bin\ ? How to undefine a variable: ?undef MyVariable ? To define variables on the command line, you can type a commandsimilar to the following:candle.exe -dMyVariable "Hello World" .You can refer to variables in your source that are defined only on thecommand line, but candle.exe will err when preprocessing your sourcecode if you do not define those variables on the command line.

Conditional StatementsThere are several conditional statements, they include: ?if ? ?ifdef ? ?ifndef ? ?else? ?elseif ? ?endif? The purpose of the conditional statement is to allow you to include orexclude a segment of xml at build time. If the expression evaluates totrue, it will be included. If it evaluates to false, it will be ignored.The conditional statements always begin with either the ?if ? , ?ifdef ? , or ?ifndef ? tags. They are followed by an xml block, an optional ?else? or ?elseif ? tag, and must end with an ?endif? tag.Expressions (used in ?if ? and ?elseif ? )For example: ?if [expression]? The expression found inside the ?if ? and ?elseif ? tags is aBoolean expression. It adheres to a simple grammar that follows theserules:The expression is evaluated left to rightExpressions are case-sensitive with the following exceptions:Environmental variable namesThese keywords: and, or, notThe operator is case-insensitive.All variables must use the () syntax or else they will be considered aliteral value.If you want to use a literal (, escape the dollar sign with a second one.For example, (Variables can be used to check for existence

Variables can be compared to a literal or another variableComparisons with , ! , and are string comparisons.Comparisons with inequality operators ( , , , ) must be doneon integers.If the variable doesn't exist, evaluation will fail and an error will beraised.The operator precedence is as follows. Note that “and” and “or” have thesame precedence:""(), ( ) , , , , , ! , NotAnd, OrNested parenthesis are allowed.Literals can be surrounded by quotes, although quotes are not required.Quotes, leading, and trailing white space are stripped off literal values.Invalid expressions will cause an exception to be thrown.Variables (used in ifdef ? and ifndef ? )For example: ?ifdef [variable] ? For ifdef ? , if the variable has been defined, this statement will be true. ifndef ? works in the exact opposite way.More ExamplesNote that these examples will actually each be a no-op because therearen’t any tags between the if and endif tags. ?define ?define ?define ?define ?define ?if ?if ?if ?ifmyValue "3"? system32 (env.windir)\system32B "good var" ? C 3 ? IExist ? (var.Iexist) (var.myValue) 6 (var.myValue)! 3not "x" "y"? ? ? ?endif? !-- true -- ? ?endif? !-- false -- ? ?endif? !-- false -- ?endif? !-- true --

?if (env.systemdrive) a? ?endif? !-- false -- ?if 3 (var.myValue)? ?endif? !-- false -- ?if (var.B) "good VAR"? ?endif? !-- false -- ?if (var.A) and not (env.MyEnvVariable)? ?endif? !-- false -- ?if (var.A) Or ( (var.B) And (var.myValue) 3)? ?endif? !-- true -- ?ifdef IExist ? !-- true -- ?else? !-- false -- ?endif?

Errors and WarningsYou can use the preprocessor to show meaningful error and warningmessages using, ?error error-message ? and ?warning warningmessage? . When one of these preprocessor instructions isencountered the preprocessor will either display an error and stop thecompile or display a warning and continue.An example: ?ifndef RequiredVariable ? ?error RequiredVariable must be defined ? ?endif?

Iteration StatementsThere is a single iteration statement, ?foreach variable-name in semicolon-delimited-list ? ?endforeach? . When this occurs thepreprocessor willcreate a private copy of the variable contextset the variable in the foreach statement to an iteration on the semicolondelimited listgenerate a fragment with the variable substitutedThe effect of this process is that the fragment is used as a template bythe preprocessor in order to generate a series of fragments. The variablename in the ?foreach statement can be preceded by "var.". When avariable is used inside the text of the fragment, it must be preceded by"var."An few examples: ?foreach LCID in "1033;1041;1055"? Fragment Id 'Fragment. (var.LCID)' DirectoryRef Id 'TARGETDIR' Component Id 'MyComponent. (var.LCID)' / /DirectoryRef /Fragment ?endforeach? or ?define LcidList 1033;1041;1055? ?foreach LCID in (var.LcidList)? Fragment Id 'Fragment. (var.LCID)' DirectoryRef Id 'TARGETDIR' Component Id 'MyComponent. (var.LCID)' / /DirectoryRef /Fragment ?endforeach? orfilename: ExtentOfLocalization.wxi Include

?define LcidList 1033;1041;1055? /Include and ?include ExtentOfLocalization.wxi ? ?foreach LCID in (var.LcidList)? Fragment Id 'Fragment. (var.LCID)' DirectoryRef Id 'TARGETDIR' Component Id 'MyComponent. (var.LCID)' / /DirectoryRef /Fragment ?endforeach? An alternative to the foreach process would be to write the template WiXfragment into a separate file and have another process generate theauthoring that will be passed to WiX. The greatest merit of this alternativeis that it's easier to debug.

EscapingThe preprocessor treats the character in a special way if it is followedby a or (. If you want to use a literal , use instead. Every two characters will be replaced with one. For example, will be replacedwith .

ExtensionsWiX has support for preprocessor extensions via thePreprocessorExtension class. The PreprocessorExtension can providecallbacks with context at foreach initialization, variable evaluation,function definitions, and the last call before invoking the compiler (for fullcustom preprocessing).

CompilerThe Windows Installer XML compiler is exposed by candle.exe. Candle isresponsible for preprocessing the input .wxs files into valid well-formedXML documents against the WiX schema, wix.xsd. Then, each postprocessed source file is compiled into a .wixobj file.The compilation process is relatively straight forward. The WiX schemalends itself to a simple recursive descent parser. The compiler processeseach element in turn creating new symbols, calculating the necessaryreferences and generating the raw data for the .wixobj file.

Linker (light)The Windows Installer XML linker is exposed by light.exe. Light isresponsible for processing one or more .wixobj files, retrieving metadatafrom various external files and creating a Windows Installer database(MSI or MSM). When necessary, light will also create cabinets andembed streams in the created Windows Installer database.The linker begins by searching the set of object files provided on thecommand line to find the entry section. If more than one entry section isfound, light fails with an error. This failure is necessary because the entrysection defines what type of Windows Installer database is being created,a MSI or MSM. It is not possible to create two databases from a singlelink operation.While the linker was determining the entry section, the symbols defined ineach object file are stored in a symbol table. After the entry section isfound, the linker attempts to resolve all of the references in the section byfinding symbols in the symbol table. When a symbol is found in a differentsection, the linker recursively attempts to resolve references in the newsection. This process of gathering the sections necessary to resolve all ofthe references continues until all references are satisfied. If a symbolcannot be found in any of the provided object files, the linker abortsprocessing with an error indicating the undefined symbol.After all of the sections have been found, complex and reversereferences are processed. This processing is where Components andMerge Modules are hooked to their parent Features or, in the case ofMerge Modules, Components are added to the ModuleComponentstable. The reverse reference processing adds the appropriate Featureidentifier to the necessary fields for elements like, Shortcut, Class, andTypeLib.Once all of the references are resolved, the linker processes all of therows retrieving the language, version, and hash for referenced files,calculating the media layout, and including the necessary standardactions to ensure a successful installation sequence. This part of theprocessing typically ends up generating additional rows that get addedassociated with the entry section to ensure they are included in the finalWindows Installer database.

Finally, light works through the mechanics of generating IDT files andimporting them into the Windows Installer database. After the database isfully created, the final post processing is done to merge in any MergeModules and create a cabinet if necessary. The result is a fully functionalWindows Installer database.

Usage Informationlight.exe [-?] [-b basePath] [-nologo] [-out outputFile] objectFile [objectFilLight supports the following command line parameters:SwitchMeaning-aiAllow identical rows; identical rows will be treated as awarning-auAllow unresolved references; this will cause invalid outputto be created-bSpecify a base path to locate all files; the default value isthe current working directory-bfBind files into a wixout; this switch is only valid when alsoproviding the -xo option-ccSpecify a path to cache built cabinet files; the path will notbe deleted after linking-ct N Specify the number of threads to use when creatingcabinets; the default is the%NUMBER OF PROCESSORS% environment variable-cultures: cultures Specifies a semicolon or comma delimited list of localizedstring cultures to load from .wxl files and libraries.Precedence of cultures is from left to right. For moreinformation see Specifying cultures to build.-cubProvide a .cub file containing additional internal

consistency evaluators (ICEs) to run-d name Define a WiX variable value -extSpecify an extension assembly-fvAdd a FileVersion attribute to each assembly in theMsiAssemblyName table (rarely needed)-loc loc.wxl Provide a .wxl file to read localization strings from-nologoSkip printing Light logo information-notidyPrevent Light from deleting temporary files after linking iscomplete (useful for debugging)-outSpecify an output file; by default, Light will write to thecurrent working directory-pedanticDisplay pedantic output messages-reusecabReuse cabinets from the cabinet cache instead ofrebuilding cabinets-saSuppress assemblies: do not get assembly nameinformation for assemblies-saclSuppress resetting ACLs (useful when laying out animage to a network share)-sadminSuppress adding default Admin sequence actions-sadvSuppress adding default Advt sequence actions

-sdutSuppress dropping unreal tables to the output image; thisswitch is set by default when the -xo switch is provided-sice: ICE Suppress running internal consistency evaluators (ICEs)with specific IDs-smaSuppress processing the data in the MsiAssembly table-sfSuppress files: do not get any file information; this switchis equivalent to the combination of the -sa and -shswitches-shSuppress file information: do not get hash, version,language and other file properties-slSuppress layout creation-ssSuppress schema validation for documents; this switchprovides a performance boost during linking-suiSuppress adding default UI sequence actions-svSuppress intermediate file version mismatch checking-svalSuppress MSI/MSM validation-sw N Suppress warnings with specific message IDs-tsTag sectionId attribute on rows; this switch is set bydefault when the -xo switch is provided-tsaTag sectionId attribute on rows and generate the rowswhen null; this switch is set by default when the -xo switch

is provided-usfSpecify an unreferenced symbols file output.xml -vGenerate verbose output-wxTreat warnings as errors-xoGenerate XML output instead of an MSI-?Display Light help information

Binder VariablesStandard Binder VariablesSome properties are not available until the linker is about to generate, orbind, the final output. These variables are called binder variables andsupported binder variables are listed below.All Versioned FilesThe following standard binder variables are available for all versionedbinaries.Variable nameExample usageExample valuebind.fileLanguage.FileID !(bind.fileLanguage.MyFile) le)1.0.0.0AssembliesThe following standard binder variables are available for all managed andnative assemblies (except where noted), where the File/@Assemblyattribute is set to ".net" or "win32".Variable nameExample usagebind.assemblyCulture.FileID(managed Name.MyAssembly)

(managed D en.MyAssebind.assemblyType.FileID(native alization VariablesVariables can be passed in before binding the output file from a WiXlocalization file, or .wxl file. This process allows the developer to link oneor more .wixobj files together with diferent .wxl files to produce differentlocalized packages.Localization variables are in the following format:!(loc.VariableName)Custom Binder VariablesYou can create your own binder variables using the WixVariable elementor by simply typing your own variable name in the following format:!(bind.VariableName)Custom binder variables allow you to use the same .wixobj files butspecify different values when linking, similar to how localization variablesare used. You might use binder variables for different builds, like varyingthe target processor architecture.

Library Tool (lit)Lit is the WiX library creation tool. It can be used to combine multiple.wixobj files into libraries that can be consumed by light.

Usage Informationlit.exe [-?] [-nologo] [-out libraryFile] objectFile [objectFile .]Lit supports the following command line parameters:SwitchMeaning-bSpecify a base path to locate all files; the default value is thecurrent working directory-bfBind files into the library file-extSpecify an extension assembly-locProvide a .wxl file to read localization strings from loc.wxl -nologoSkip printing Lit logo information-outSpecify an output file; by default, Lit will writ

Windows Installer XML Files - .wxs & .wixobj A .wxs file is used by all source files in the Windows Installer XML system. These .wxs files are analogous to .cpp files for C or .cs files for C#. The .wxs files are preprocessed and then compiled into WiX object files, which use the extension .wixobj. When all of the source files