In this tutorial I'm going to show how to automate of changing web.config file when it get deployed to different destination.
Default transformation files
In Solution Explorer, expand Web.config to see the Web.Debug.config and Web.Release.config transformation files that are created by default for the two default build configurations.
Lets get to a real time scenario. We going to change the settings on Web.config.
For example,
1. On Development we want to set custom error to be OFF to enable developers to view detailed info about the application error.
2. On Production we want to set custom error to be ON to prevent external users from viewing detailed info about the application error.
Web.config
So basically you want to set CustomErrors Mode=ON
Web.Production.config
Next, set bellow properties on the Web.Production.config file.
- Build Action - Content
- Copy to Output Directory - Do not copy
This is how it looks in .csproj file
There is a preview option in Visual Studio that allows us to check out how it gets transformed.
To do that follow bellow steps,
1. Copy content from Web.Production.config to Web.Release.config
2. Right click on Web.Release.config and click Preview
We can view the difference.
So next time when you publish, this transformation should get applied.
Here are few useful links.
That's it. Enjoy !!
Here are few useful links.
- Xdt Transform Samples
- Web config transformation tester
- Web.config File Transformations - Microsoft Docs
That's it. Enjoy !!
Add a comment