Using different Web.config in development and production environment?

In Visual Studio 2010, 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: Web.Debug. Config Web.Release. Config They contains transformation code that can be used to Change the connection string Remove debugging trace and settings Register error pages See msdn.microsoft.com/en-us/library/dd46532...).Aspx 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.

The 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; Note: Changes to the . Config specified by the attribute won't trigger a restart of the asp.net worker process.

microsoft.com/downloads/details.aspx?Fam... There is a version for VS2005 as well, if you are not on 2008.

This is a good guide for using web deployment projects : johnnycoder.com/blog/2010/01/07/… – Gary W Mar 28 '10 at 22:23.

I'd like to know, too. This helps isolate the problem for me 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.).

If youd be using VS you could use prebuild-events to copy from a debug. Connectionstrings. Config or a release.

Connectionstrings. Config like: copy $(ProjectDir)$(ConfigurationName)ConnectionStrings. Config $(ProjectDir)ConnectionStrings.

Config as suggested by Scott. Hanselmann: hanselman.com/blog/… – Thomas Jan 4 '10 at 13:42.

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.

Please read vishaljoshi.blogspot.com/2009/03/web-dep... which is VS 2010 solution for dealing with your exact problem...

11 @Vishal, while your blog posts are always excellent, the preference here on StackOverflow is for answers to contain more than just links. Not that you should reproduce your entire blog post here, but a summary of the post would be a good addition to your answer. That may be why one of your answers has already been downvoted.

– John Saunders Aug 14 '09 at 5:02.

The Enterprise Library configuration editor can help you do this. It allows you to create a base config file and then deltas for each environment. You can then merge the base config and the delta to create an environment-specific web.config.

Take a look at the information here which takes you through it better than I can.

You could also make it a post-build step. Setup a new configuration which is "Deploy" in addition to Debug and Release, and then have the post-build step copy over the correct web.config. We use automated builds for all of our projects, and with those the build script updates the web.

Config file to point to the correct location. But that won't help you if you are doing everything from VS.

This is one of the huge benefits of using the machine.config. At my last job, we had development, test and production environments. We could use the machine.

Config for things like connection strings (to the appropriate, dev/test/prod SQL machine). This may not be a solution for you if you don't have access to the actual production machine (like, if you were using a hosting company on a shared host).

On one project where we had 4 environments (development, test, staging and production) we developed a system where the application selected the appropriate configuration based on the machine name it was deployed to. This worked for us because: administrators could deploy applications without involving developers (a requirement) and without having to fiddle with config files (which they hated); machine names adhered to a convention. We matched names using a regular expression and deployed to multiple machines in an environment; and we used integrated security for connection strings.

This means we could keep account names in our config files at design time without revealing any passwords. It worked well for us in this instance, but probably wouldn't work everywhere.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions