Add setting to web.config and then create one configuration file per environment e.g. web.DEV.config,web.Test.Config,web.UAT.config,web.Production.Config
Each of these configuration files will contain environment specific settings which we want to apply to base web.config such as connection strings,service endpoints etc.
To generate final web.config, we need to set xml transformation rules in these web.config.
e.g.
<add name="Test" connectionString="newConnectionString" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
<replaceAll>
<endpointAddresses
xdt:Locator="XPath(/configuration/system.serviceModel//*@contract='Contract1Name'])"
xdt:Transform="SetAttributes(address)" address="newEndpointAddress" />
</replaceAll>
If we want to replace entire section:
<system.web>
<compilation targetFramework="4.0" xdt:Transform="Replace">
<assemblies>
<add assembly="AssemblyName, Version=VersionInfo, Culture=neutral, PublicKeyToken=publicToken" />
</assemblies>
</compilation>
</system.web>
<add name="Test" connectionString="newConnectionString" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
Each of these configuration files will contain environment specific settings which we want to apply to base web.config such as connection strings,service endpoints etc.
To generate final web.config, we need to set xml transformation rules in these web.config.
e.g.
<add name="Test" connectionString="newConnectionString" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
<replaceAll>
<endpointAddresses
xdt:Locator="XPath(/configuration/system.serviceModel//*@contract='Contract1Name'])"
xdt:Transform="SetAttributes(address)" address="newEndpointAddress" />
</replaceAll>
If we want to replace entire section:
<system.web>
<compilation targetFramework="4.0" xdt:Transform="Replace">
<assemblies>
<add assembly="AssemblyName, Version=VersionInfo, Culture=neutral, PublicKeyToken=publicToken" />
</assemblies>
</compilation>
</system.web>
<add name="Test" connectionString="newConnectionString" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />