.netweb-configweb.config-transform

web.config transforms for <applicationSettings>


I have web.config transforms for several environments. In the config file I have an applicationSettings section with several setting and value pairs.

I have tried based on the syntax I use to match name and change the connection strings to also match settings and change the value but the transforms are failing. Is this at all possible?

So my web.config has:

<applicationSettings>
    <AppName.My.MySettings>
        <setting name="setting1" serializeAs="String">
            <value>Initial Value</value>
        </setting>
    </AppName.My.MySettings>
</applicationSettings>

My transform file has

<applicationSettings>
    <add name="setting1" value="Changed Value" xdt:Transform="SetAttributes" xdt:Location="Match(name)"/>
</applicationSettings>

I get no errors when I preview the transform but whereas the connection string setting are transformed the value for setting1 is not. Any help appreciated.

UPDATE

<applicationSettings>
    <add name="setting1" value="Changed Value" xdt:Transform="Replace" xdt:Location="Match(name)"/>
</applicationSettings>

Unfortunately same problem... No errors and no transform.

SOLUTION I did forget to mention I have more than one setting so marked answer is partial solution... This is how I did it... Web.Config...

<applicationSettings>
    <AppName.My.MySettings>
        <setting name="setting1" serializeAs="String">
            <value>Initial Value 1</value>
        </setting>
        <setting name="setting2" serializeAs="String">
            <value>Initial Value 2</value>
        </setting>
        <setting name="setting3" serializeAs="String">
            <value>Initial Value 3</value>
        </setting>
    </AppName.My.MySettings>
</applicationSettings>

Transform File

<applicationSettings xdt:Transform="Replace">
    <AppName.My.MySettings>
        <setting name="setting1" serializeAs="String">
            <value>CHANGED VALUE 1</value>
        </setting>
        <setting name="setting2" serializeAs="String">
            <value>Initial value 2</value>
        </setting>
        <setting name="setting3" serializeAs="String">
            <value>CHANGED VALUE 3</value>
        </setting>
    </AppName.My.MySettings>
</applicationSettings>

Note I had to include all my nested settings and values even if some of them didn't change as in the case of setting 2 in my example.


Solution

  • original file:

    <applicationSettings>
        <AppName.My.MySettings>
            <setting name="setting1" serializeAs="String">
                <value>Initial Value</value>
            </setting>
        </AppName.My.MySettings>
    </applicationSettings>
    

    Transform file:

     <applicationSettings>
       <AppName.My.MySettings>
          <setting name="setting1" serializeAs="String">
               <value xdt:Transform="Replace">Changed Value</value>
           </setting>
        </AppName.My.MySettings>
      </applicationSettings>