In Visual Studio 2010 and above, you now have the ability to apply a transformation to your web.config depending on the build configuration.
When creating a web.config, you can expand the file in the solution explorer, and you will see two files:
They contain transformation code that can be used to
See Web.config Transformation Syntax for Web Application Project Deployment on MSDN for more information.
It is also possible, albeit officially unsupported, to apply the same kind of transformation to an non web application app.config
file. See Phil Bolduc blog concerning how to modify your project file to add a new task to msbuild.
This is a long withstanding request on the Visual Studio Uservoice.
An extension for Visual Studio 2010 and above, "SlowCheetah," is available to take care of creating transform for any config file. Starting with Visual Studio 2017.3, SlowCheetah has been integrated into the IDE and the code base is being managed by Microsoft. This new version also support JSON transformation.
The <appSettings>
tag in web.config supports a file attribute that will load an external config with it's own set of key/values. These will override any settings you have in your web.config or add to them.
We take advantage of this by modifying our web.config at install time with a file attribute that matches the environment the site is being installed to. We do this with a switch on our installer.
eg;
<appSettings file=".\EnvironmentSpecificConfigurations\dev.config">
<appSettings file=".\EnvironmentSpecificConfigurations\qa.config">
<appSettings file=".\EnvironmentSpecificConfigurations\production.config">
Note:
Have you looked in to web deployment projects?
http://www.microsoft.com/downloads/details.aspx?FamilyId=0AA30AE8-C73B-4BDD-BB1B-FE697256C459&displaylang=en
There is a version for VS2005 as well, if you are not on 2008.
I'd like to know, too. This helps isolate the problem for me
<connectionStrings configSource="connectionStrings.config"/>
I then keep a connectionStrings.config as well as a "{host} connectionStrings.config". It's still a problem, but if you do this for sections that differ in the two environments, you can deploy and version the same web.config.
(And I don't use VS, btw.)
I use a NAnt Build Script to deploy to my different environments. I have it modify my config files via XPath depending on where they're being deployed to, and then it automagically puts them into that environment using Beyond Compare.
Takes a minute or two to setup, but you only need to do it once. Then batch files take over while I go get another cup of coffee. :)
Here's an article I found on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With