Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I transform web.config values?

I am trying to make different config files for different cases (debug,release, etc.) and I would like to change some settings for different builds.

<configuration>
<applicationSettings>
<Program1.Properties.Settings>
  <setting name="CustomerId" serializeAs="String">
    <value>Custormer1-13256</value>
  </setting>
</Program1.Properties.Settings>
</applicationSettings>
</configuration>

How can I change the value inside the tag to something else?

   ex. <value>Customer2-343242</value>
like image 833
dare2k Avatar asked Apr 22 '13 09:04

dare2k


People also ask

How do I create a Web config transform?

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 Xdt transform in web config?

The xdt:Transform attribute value "SetAttributes" indicates that the purpose of this transform is to change attribute values of an existing element in the Web. config file.

How do I rename a web config transform?

If you are using the extension Configuration Transform go to Build > Configuration Manager and find the Configuration dropdown for the project of which you want to change the app config. You can then select the edit and rename the build configurations for that project.


1 Answers

Add xdt:Locator="Match(name)" to Erwin's answer

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<applicationSettings>
    <Program1.Properties.Settings>
        <setting name="CustomerId" serializeAs="String" xdt:Transform="Replace" 
                                                             xdt:Locator="Match(name)">
            <value>Customer2-343242</value>
        </setting>
    </Program1.Properties.Settings>
</applicationSettings>

like image 107
MNBob Avatar answered Sep 22 '22 15:09

MNBob