HowTo to set appsettings during installation using WIX

The point where most people have a hard time is remembering is to escape brackets. This to ensure WIX will not think it a property. If you forget to-do this you may end up in a situation where “config2” value will bet set on “config1” instead. See a correct example bellow

[ should be [\[]
] =should be [\]]

<Component Id='UpdateConfig' Guid='A89D47AF-7DBE-4a8d-9848-F35C78FD95ED' DiskId='1' KeyPath="yes">
  <util:XmlFile Id='config1' 
                Action="setValue" 
                ElementPath="//configuration/appSettings/add[\[]@key='FirstKey'[\]]/@value"
                File="[INSTALLDIR]Web.config" 
                Value="[NEWVALUE1]" />
  <util:XmlFile Id='config2' 
                Action="setValue" 
                ElementPath="//configuration/appSettings/add[\[@key='SecondKey'[\]]/@value"
                File="[INSTALLDIR]Web.config" 
                Value="[NEWVALUE2]" />
</Component>

And the example web.config

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="FirstKey" value="oldvalue"/>
    <add key="SecondKey" value="oldvalue"/>
  </appSettings>
</configuration>
2.40 avg. rating (53% score) - 5 votes

About Peter Wibeck

Comments

One Response to “HowTo to set appsettings during installation using WIX”
  1. Rudolph says:

    Dude, awesome advice! Really helped me a lot!
    Thank you.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

*