Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 770
Mych Avatar asked Jul 03 '15 13:07

Mych


People also ask

What is Web config transform?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

What is Xdt transform in Web config?

A transform file is an XML file that specifies how the Web. config file should be changed when it is deployed. Transformation actions are specified by using XML attributes that are defined in the XML-Document-Transform namespace, which is mapped to the xdt prefix.

How do I create a new transformation in Web config?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).

What is a web config transformation file?

A Web.config transformation file contains XML markup that specifies how to change the Web.config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

How do I automate the process of changing web config settings?

There are two ways to automate the process of changing Web.config file settings: Web.config transformations and Web Deploy parameters. A Web.config transformation file contains XML markup that specifies how to change the Web.config file when it is deployed.

What is the difference between web config and app config files?

Not everyone knows that Web.config and App.config files are actually two different file types, maintained by different people (at least that's what I've heard) but that share common elements. This means that App.config files are not supported out of the box.

How do I transform a Visual Studio app config file?

After restarting Visual Studio, right-clicking a App.config file will now show the Add Transform option: SlowCheetah needs to install a NuGet package in order to transform the file on build. A nice feature of installing the Visual Studio package first is this:


1 Answers

I know this is a little late, but the following transform file will allow you transform just one setting when you have multiple.

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <applicationSettings>
    <YourProject.Settings>
      <setting name="Log4NetPath" serializeAs="String" xdt:Transform="Replace" xdt:Locator="Match(name)">
        <value xdt:Transform="Replace">NewPath</value>
      </setting>
    </YourProject.Settings>
  </applicationSettings>
</configuration>
like image 192
Dvirus1023 Avatar answered Sep 23 '22 19:09

Dvirus1023