Global settings files in WiX
Global settings files have several requirements:
-
On install, create the file if it does not exist.
-
Configure certain settings during installation/upgrade, and leave all other settings alone.
-
Never delete the settings file during installation, upgrade, or uninstallation.
With these requirements, we have the following fragment:
<Component Id="settings.config" NeverOverwrite="yes" Permanent="yes">
<File Source="path/to/default/settings.config" KeyPath="yes" />
</Component>
<Component Id="settings.config.Configure" KeyPath="yes" Guid="...">
<util:XmlConfig File="[#settings.config]" .... Value="[PROPERTY1]" />
<util:XmlConfig File="[#settings.config]" .... Value="[PROPERTY2]" />
</Component>
Here’s how this meets all the requirements:
-
The
settings.config
component creates the file if the component isn’t installed when we start the installation. -
During installation and upgrade, the second component will modify the existing
settings.config
that’s on disk. The settingComponent/@NeverOverwrite
prevents us from overwriting the existing file on upgrade. -
During uninstallation, the file is left in place with
Component/@Permanent
. This attribute also prevents the file from being removed even ifMajorUpgrade/@Schedule='afterInstallValidate'
. -
The
XmlConfig
actions are in a separate component so they will run on upgrades even thoughsettings.config
isn’t being updated.