Wix:Examples

From IrohWiki

Jump to: navigation, search
WiX Windows Installer XML
Part of the WiX Tool

View or Edit Template



Microsoft Technologies
Part of Microsoft reference pages.

View or Edit Template


Contents


Wix version 2.x

Properties

Declare:

<Property Id="PropertyName" Value="PropertyValue" />
<Property Id="PropertyName" >PropertyValue</Property>

Use:

To Get Syntax
Property [PropertyName]
Environment Variable (Case insensitive) [%VarName]
Component Action State [$ComponentName]
Component Installed State [?ComponentName]
Feature Action State [&FeatureName]
Feature Installed State [!FeatureName]

Action State and Installed State Values:

Value Meaning
-1 no action to be taken
1 advertised (only for components)
2 not present
3 on the local computer
4 run from the source

Examples:

<!-- FeatureName is to be installed locally -->
<Condition>(&FeatureName = 3)                           </Condition>

<!-- FeatureName not installed locally -->
<Condition>                       NOT (!FeatureName = 3)</Condition>

<!-- Run action only if the product will be installed locally. Do not run action on a reinstallation. -->
<Condition>(&FeatureName = 3) AND NOT (!FeatureName = 3)</Condition> 

<!-- Run action only if the feature will be uninstalled. -->
<Condition>(&FeatureName = 2) AND (!FeatureName = 3)</Condition> 

Modify a Property (Custom Action)

This adds a custom action that will change the value of a property.

<Property Id="PropertyName" 
Value="Initial Property Value. Things in brackets are not evaulated, like [AnotherProperty]." />
 
<Property Id="AnotherProperty" Value="Another Property's Value" />
 
<CustomAction Id="SetPropertyValue" Property="PropertyName"
Value="New Value. Brackets are evaulated, like [AnotherProperty]." Return="check" />

before the custom action PropertyName is equal to "Initial Property Value. Things in brackets are not evaulated, like [AnotherProperty].".

After the custom action PropertyName is equal to "New Value. Brackets are evaulated, like Another Property's Value."

Global Properties

If a properties ID is in all caps, this means it is a Global Property. Most of the time it makes no difference at all weather the property is global or not; on occasion, it will.

Some situations where a property needs to be global:

  1. When writing a property who's value has changed since the installer started out to an XML file using the <XMLFile ... > element.
    • If the property is not global, it will not write the latest value of the property.

Add/Remove Programs Settings Special Properties

<Property Id='ARPCOMMENTS'     >any comments</Property>
<Property Id='ARPCONTACT' >contact info</Property>
<Property Id='ARPHELPLINK' >URL for technical support</Property>
<Property Id='ARPURLINFOABOUT' >URL for general info about the product</Property>
<Property Id='ARPURLUPDATEINFO'>URL for product updates</Property>
<Property Id='ARPHELPTELEPHONE'>URL for technical support</Property>
<Property Id='ARPREADME' >Path to Readme Document</Property>
<Property Id='ARPSIZE' >app size in kilobytes</Property>
 
<Icon Id="appicon.ico" SourceFile="Application.ico" />
<Property Id='ARPPRODUCTICON'>appicon.ico</Property>
 
<!-- To suppress the Modify button -->
<Property Id='ARPNOMODIFY'>1</Property>
 
<!-- To disable the Remove button -->
<Property Id='ARPNOREMOVE'>1</Property>
 
<!-- remove the application altogether from this list -->
<Property Id='ARPSYSTEMCOMPONENT'>1</Property>
 
<!-- suppress the Repair functionality -->
<Property Id='ARPNOREPAIR'>1</Property>

Directories

The directories section describes how source files map to target files on the target computer.

Note: if you reference a folder, even a predefined 'System Folder Property', you must include it in your directory section.

In the examples below assume each is property under a <Wix ... > and <Product ... > tag

Predefined Folders

Here are some of the predefined folders.

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" />
<Directory Id="CommonAppDataFolder" />
<Directory Id="SystemFolder" />
<Directory Id="StartupFolder" />
<Directory Id="DesktopFolder" />
<Directory Id="ProgramMenuFolder" />
</Directory>

System Folder Properties

This list is from System Folder Properties under the Windows Installer Guide on MSDN.

Property System Default Path (En-US) Description
AdminToolsFolder The full path to the directory that contains administrative tools.
AppDataFolder C:\Documents and Settings\[UserName]\Application Data The full path to the Roaming folder for the current user.
CommonAppDataFolder C:\Documents and Settings\All Users\Application Data The full path to application data for all users.
CommonFiles64Folder The full path to the predefined 64-bit Common Files folder.
CommonFilesFolder The full path to the Common Files folder for the current user.
DesktopFolder C:\Documents and Settings\[UserName]\Desktop The full path to the Desktop folder.
FavoritesFolder C:\Documents and Settings\[UserName]\Favorites The full path to the Favorites folder for the current user.
FontsFolder C:\WINDOWS\Fonts The full path to the Fonts folder.
LocalAppDataFolder The full path to the folder that contains local (nonroaming) applications.
MyPicturesFolder C:\Documents and Settings\[UserName]\My Documents\My Pictures The full path to the Pictures folder.
PersonalFolder The full path to the Documents folder for the current user.
ProgramFiles64Folder The full path to the predefined 64-bit Program Files folder.
ProgramFilesFolder C:\Program Files The full path to the predefined 32-bit Program Files folder.
ProgramMenuFolder C:\Documents and Settings\[UserName]\Start Menu\Programs The full path to the Program Menu folder.
SendToFolder C:\Documents and Settings\[UserName]\SendTo The full path to the SendTo folder for the current user.
StartMenuFolder C:\Documents and Settings\[UserName]\Start Menu The full path to the Start menu folder.
StartupFolder C:\Documents and Settings\[UserName]\Start Menu\Programs\Startup The full path to the Startup folder.
System16Folder The full path to folder for 16-bit system DLLs.
System64Folder The full path to the predefined System64 folder.
SystemFolder The full path to the System folder for the current user.
TempFolder The full path to the Temp folder.
TemplateFolder The full path to the Template folder for the current user.
WindowsFolder C:\WINDOWS The full path to the Windows folder.
WindowsVolume The volume of the Windows folder.

Custom Folders

Here is how you create a folder under program files.

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" />
<Directory Id="INSTALLDIR" Name="SFN1" LongName="Some Folder Name 1">
</Directory>
</Directory>
</Directory>

The directory structure under after this is installed would look like this: C:\Program Files\Some Folder Name 1

Conditions

Detecting the OS Version

<Condition Message='Windows 95'          >Version9X = 400                          </Condition>
<Condition Message='Windows 95 OSR2.5' >Version9X = 400 AND WindowsBuild = 1111 </Condition>
<Condition Message='Windows 98' >Version9X = 410 </Condition>
<Condition Message='Windows 98 SE' >Version9X = 410 AND WindowsBuild = 2222 </Condition>
<Condition Message='Windows ME' >Version9X = 490 </Condition>
<Condition Message='Windows NT4' >VersionNT = 400 </Condition>
<Condition Message='Windows NT4 SPn' >VersionNT = 400 AND ServicePackLevel = n </Condition>
<Condition Message='Windows 2000' >VersionNT = 500 </Condition>
<Condition Message='Windows 2000 SPn' >VersionNT = 500 AND ServicePackLevel = n </Condition>
<Condition Message='Windows XP' >VersionNT = 501 </Condition>
<Condition Message='Windows XP SPn' >VersionNT = 501 AND ServicePackLevel = n </Condition>
<Condition Message='Windows Server 2003' >VersionNT = 502 </Condition>

Detecting the Microsoft .NET Framework

This will only check the Highest version of the .NET Framework installed.

<Condition Message=".Net Framework 2.0">MsiNetAssemblySupport >= "2.0.50727"</Condition>

Launch an application (Custom Action)

This adds a custom action that will launch an external application

<CustomAction Id="LaunchApp" Directory="SystemFolder" ExeCommand="calc.exe" Return="asyncNoWait" />
Directory: Can be any directory predefined by the Windows Installer 3.1 or one you define under your <Directory ... > section.
ExeCommand: Any executable file name. No path. Parameters can be included by adding a space after the exe file and then placing the parameters (just like you would type it in a DOS prompt).

Modify an XML File

These examples show how to manipulate XML files using the WiX tool.

In order to use the XML custom actions, you have to add a reference to the WiX General Custom Actions (WixCA) library:

wixca.wixlib

The below examples use the following settings.xml code as the baseline:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Setting1" value="SettingValue1" />
<add key="Setting2" value="SettingValue2" />
<add key="Setting3" value="SettingValue3" />
<add key="Setting4" value="SettingValue4" />
</appSettings>
</configuration>
Note: If you examine the examples below closely, you will notice that the structure does not change in modified files, but the whitespace does. Depending on what you do, some line feeds and spaces will disappear. This is almost always irrelevant, but is good to know.


Create an Element

Assume that this code is property under a <Directory Id="DesktopFolder"> element in a WiX file.

<Component ... >
<File Id="SettingsXmlFile" Name="SETTINGS.XML" LongName="Settings.xml" Source="settings.xml" DiskId="1" Vital="yes" />
 
<XmlFile Id="xmlModifyTest2.1" Action="createElement"
ElementPath="/configuration/appSettings" Name="add"
File="[DesktopFolder]Settings.xml" Sequence="10" />
</Component>
Modified Settings File: settings.xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Setting1" value="SettingValue1"/>
<add key="Setting2" value="SettingValue2"/>
<add key="Setting3" value="SettingValue3"/>
<add key="Setting4" value="SettingValue4"/>
<add/></appSettings>
</configuration>

Modify an Element Attribute

This code will modify a specific attribute in a specific element with a specific attribute value. Here, there are 4 <add elements and we want to modify specific ones; the key="Settings2" and key="Settings3", the middle two.

Assume that this code is property under a Directory element in a WiX file.

<Component ... >
<File Id="SettingsXmlFile" Name="SETTINGS.XML" LongName="Settings.xml" Source="settings.xml" DiskId="1" Vital="yes" />
 
<XmlFile Id="xmlModifyTest2.2aa" Action="setValue"
ElementPath="/configuration/appSettings/add[\[]@key='Setting2'[\]]" Name="value" Value="Written Value 2.2aa"
File="[DesktopFolder]Settings.xml" Sequence="11" />
 
<XmlFile Id="xmlModifyTest2.3aa" Action="setValue"
ElementPath="/configuration/appSettings/add[\[]@key='Setting3'[\]]" Name="value" Value="Written Value 2.3aa"
File="[DesktopFolder]Settings.xml" Sequence="12" />
</Component>
Modified Settings File: settings.xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Setting1" value="SettingValue1"/>
<add key="Setting2" value="Written Value 2.2aa"/>
<add key="Setting3" value="Written Value 2.3aa"/>
<add key="Setting4" value="SettingValue4"/>
</appSettings>
</configuration>

Wix version 3.x

Personal tools