Using different Web.config in development and production environment

I need to use different database connection string and SMTP server address in my ASP.NET application depending on it is run in development or production environment.

The application reads settings from Web.config file via WebConfigurationManager.AppSettings property.

I use Build/Publish command to deploy the application to production server via FTP and then manually replace remote Web.config with correct one.

Is it possible somehow simplify the process of deployment? Thanks!


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:

  • 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 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.

A new extension for Visual Studio 2010 and above, "SlowCheetah," is available to take care of creating transform for any config file.

Need Your Help

Image resolution support for iPhone 3G, iPhone 4 and iPhone 5

objective-c ios uikit screen-resolution iphone-5

I know that similar questions have been asked before, but I am really in a dire situation.

Binding a map of lists in Spring MVC

java jsp spring-mvc jstl

I am not sure if this is a complex problem but as a starting person this seems a bit complex to me.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.