Reputation: 63
I'm using a web.config transform to change a link in the production environment but when previewing it, the transformation doesn't happen..
Here is my code:
web.Test.config
<configuration>
<appSettings>
<add key ="ELeg" value ="1"/>
</appSettings>
</configuration>
<system.web>
web.Prod.config
<configuration>
<appSettings>
<add key ="ELeg" value="10" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
When previewing it on the prod and test envoirment, it doesnt add the appSetting.
Does anyone know what the problem is?
UPDATE
Here is my entire Test transform:
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<configuration>
<appSettings>
<add key ="ELeg" value ="1" xdt:Transform="Insert" />
</appSettings>
</configuration>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
Upvotes: 2
Views: 3746
Reputation: 181077
You don't have a key=10
to match on, you have a key=ELeg
;
In other words, this (untested) transform should work better;
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key ="ELeg" value ="10" xdt:Transform="SetAttributes(value)" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
Explanation of the transform attributes
xdt:Locator="Match(key)" // Find elements with matching `key`.
xdt:Transform="SetAttributes(value)" // Set the `value` attribute on the matches
EDIT: If you want to insert it and it does not even exist, then a plain xdt:Transform="Insert"
is what you want;
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key ="ELeg" value ="10" xdt:Transform="Insert" />
</appSettings>
</configuration>
Upvotes: 5
Reputation: 420
Below will transform the value of the ELeg setting to 10:
<add xdt:Transform="Replace" xdt:Locator="Match(key)" key="ELeg" value="10" />
Upvotes: 1