Test vs production configuration files (web.config)

I have different databases that I would like to connect to while running unit tests vs. production. Does anyone have a good solution to the conflicting web.config problem?

Comment actions Permalink

I know this is a bit off topic but we should all be here to help.

As you have found, web.config/app.config do not cope well with multiple environments.

I faced the same challenge a while ago, but with a few more environments: Dev, Test, Prod, DRTest, DRProd!

After much investigation and head scratching I found the Nini configuration library (See my blog post on Nini at http://extraview.co.uk/blog/PermaLink,guid,604fbe89-a927-4863-94d3-869c54cda092.aspx). The downside to an external configuration library is that you lose features like built in framework support of the ConnectionStrings section. However, for me, the significant benefits in being able to use and merge multiple configuration files outweigh these little challenges.

We tend to use an environment variable to allow the application to select the correct environment configuration file.

Take a look, you won't be disappointed.

Comment actions Permalink

We use a nant build script with different build configurations to copy the appropriate config file to the build folder.

For example, we name our config files like:

And then setup 3 build configurations (one for each target). Then it's a fairly simple nant script to select, copy, and rename the appropriate build file which is wired up in the post-build event of the project.

Comment actions Permalink

And you could also look at the "Web deployment" project, assuming you are using VS2005, which amongst other features, supports per build configuration updates to the web.config file.



Please sign in to leave a comment.