This article shows how to automate the process of transforming the configuration file like App.config, Web.config file when we deploy it to the different destination environments like Dev, Stg, Prod. Most applications have settings in the App.config or Web.config file that must be different when the application is deployed. Automating the process of making these changes saves us from having to do them manually every time we deploy, which would be tedious and error prone.
In most real-world scenarios, the configuration (app.config, web.config) file we use for development is different than the one we use for production deployment. Typically we want to change environment settings from the development environment to the production environment. From .Net 4.0 XDT Transformation is come into play to do this type of transformation.
Create a console app 'ConfigurationTransform' from visual studio.
Now add appsettings block in configuration section in App.config as
Add xml namespace attribute 'xmlns:xdt' in App.Dev.config file as
Now build the solution and go to ../bin/Dev folder and click on 'ConfigurationTransform.exe'. It will print transformed configuration value as
You can add more configuration for different environment like QA, Stg, Prod.