HowTo add new key to appsettings with WIX
When adding a new key for appsettings you need to split the action in 3 steps.
1. Create the new empty “add” element
2. Create and set the “key” attribute. The tricky part here is how to add the “key” to new created “add” element from step one. One way is to assume that the new created “add” element is the only element without a “key” attribute
3. Create and set the “value” attribute.
<util:XmlFile Id='conf1' Action="createElement" ElementPath="//configuration/appSettings" Name="add" File="[INSTALLDIR]Web.config" Sequence="1" /> <util:XmlFile Id='conf2' Action="setValue" ElementPath="//configuration/appSettings/add[\[]not(@key)[\]]" Name="key" Value="NewConfig" File="[INSTALLDIR]Web.config" Sequence="2" /> <util:XmlFile Id='conf3' Action="setValue" ElementPath="//configuration/appSettings/add[\[]@key='NewConfig'[\]]" Name="value" Value="the new value" File="[INSTALLDIR]Web.config" Sequence="3" /> |
You are the kindest soul in the known world. I’ve been searching all over for this. Thank you, wix wizard, for saving my job.