Consider we have different hosting environment like UAT, live, Dev, so we need to differentiate setting according to hosting environment.
We can you web.config transformtion for the same.
A transform file is an XML file that specifies how the Web.config file should be changed when it is deployed.
Creating and Coding a Transform File:
- Create the build configuration first by using Configuration Manager.
- In Solution Explorer, expand the application Web.config file.
If any transform files have already been created, the Web.config file is displayed in Solution Explorer with a symbol indicating that it can be expanded, and the transform files are shown when you expand the Web.config file.
- If no transform file exists for the build configuration that you want to specify settings for, in Solution Explorer, right-click the Web.config file and then click Add Config Transforms.
- Open the transform file for the build configuration that you want to work with.
- Edit the transform file to specify the changes that should be made to the deployed Web.config file when you deploy by using that build configuration.
Example: If we want to transform
1 2 3 4 5 6 7 |
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <connectionStrings> <add name="MyDB" connectionString="ReleaseSQLServer" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings> </configuration> |
References:
- https://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx
- https://msdn.microsoft.com/en-us/library/dd465326(v=vs.100).aspx