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:
settings.configcomponent 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.configthat’s on disk. The setting
Component/@NeverOverwriteprevents 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 if
XmlConfigactions are in a separate component so they will run on upgrades even though
settings.configisn’t being updated.