How To Implement web.config Transformation in Asp.Net



First of all web.config transformation can be applied to Web Application only. During web application development, we may have to deploy the application to multiple servers. In such cases, we may needs to change the web.config values as per each server requirement. We may needs to change the connection string, app settings values, file upload path, machine key web.config transformation allows us to keep specific web.config for each deployment. Instead of changing the values of one web.config on each deployment, we only have to choose the specific web.config on each deployment.



On your web application, click on the configuration manager drop down list near Run Button on Visual Studio as shown in the figure. By Default it contains Debug and Release only.

How To Implement web.config Transformation in Asp.Net, web.config Transformation, Transformation, web.config, Implement web.config Transformation, Asp.Net

On configuration manager drop down list, click on the configuration manager link. A new window will open as shown in the figure.

How To Implement web.config Transformation in Asp.Net, web.config Transformation, Transformation, web.config, Implement web.config Transformation, Asp.Net

Inside that window, on Active Solution Configuration drop down list, select New Link.
A new window will open as shown in the figure.

How To Implement web.config Transformation in Asp.Net, web.config Transformation, Transformation, web.config, Implement web.config Transformation, Asp.Net

On that window, enter a new Publish Environment Name on the Name field. Don't copy anything from the previous configurations, if you don't need. check the Create new project configurations check box. Then click OK button. Close the Configuration Manager window also.

Now go to the Solution Explorer and right click on the web.config main file. Click on the Add Config Transform link. This will automatically append the newly created web.config as shown in the figure.

How To Implement web.config Transformation in Asp.Net, web.config Transformation, Transformation, web.config, Implement web.config Transformation, Asp.Net

Now select this configuration at the time of Publish as shown in the figure.

How To Implement web.config Transformation in Asp.Net, web.config Transformation, Transformation, web.config, Implement web.config Transformation, Asp.Net





Some of the changes on the newly created web.config are specified on the following figure.

How To Implement web.config Transformation in Asp.Net, web.config Transformation, Transformation, web.config, Implement web.config Transformation, Asp.Net

As per our requirement, we can replace, insert or remove the attributes.