I'm using WiX 3.8 and trying to update my existing .config file on minor update but I'm having difficulties understanding how to achieve this.
I created a custom action to read values from the existing config file but can't figure out how to insert them into the new file?
I followed this article : Having WiX upgrade a config file with missing items (and subsequently this one : How can multiple elements be added to an XML config file with wix?) but settings don't seem to be getting overwritten with previous values, can anyone give me a pointer please?
Basically I want to preserve the settings entered by the user during installation but overwrite the rest of the config if it has changed from version to version.
I currently do this with a combination of custom action and XmlConfig.
The custom action is run after CostFinalize and reads current values from the config file(s) and saves them in public properties.
string configFile = Path.Combine(session["INSTALLLOCATION"], "app.exe.config");
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = configFile;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
session["OLD_PRESERVEDVALUE"] = config.AppSettings.Settings["PreservedValue"].Value;
then I have an XmlConfig entry like below which sets the preserved values from the public properties:
<Component Id="RestoreOldPreservedValue" Guid="<GUID>" >
<Condition>OLD_PRESERVEDVALUE</Condition>
<CreateFolder/>
<util:XmlConfig
Id='RestoreOldPreservedValue'
Action='create'
On='install'
Node='value'
ElementPath='/configuration/applicationSettings/app.Properties.Settings/setting[\[]@name="PreservedValue"[\]]/value'
File='[#app.exe.config]'
Value='[OLD_PRESERVEDVALUE]'>
</util:XmlConfig>
</Component>
My next iteration will be to have the custom action create entries in the XmlConfig table directly.
The ultimate solution would be a WiX extension that populates a custom table and schedules a custom action which saves the values to be preserved after CostFinalize, and then another custom action that restores the values after the new config file(s) have been copied by the installer.