Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you handle multiple web.config files for multiple environments?

The way I currently handle this is by having multiple config files such as:

web.config web.Prod.config web.QA.config web.Dev.config 

When the project gets deployed to the different environments I just rename the corresponding file with the correct settings.

Anyone have suggestions on how to handle this better?

EDIT: Here are some of the things that change in each config:

  • WCF Client Endpoint urls and security
  • Custom Database configs
  • Session connection strings
  • log4net settings
like image 215
Nick Avatar asked Feb 26 '09 22:02

Nick


People also ask

Can we have multiple web config file in one solution?

Yes you can have two web. config files in application. There are situations where your application is divided in to modules and for every module you need separate configuration. For example if you have a application which has two modules lets say accounts and sales.

How do you create a web config for different environments?

In order to create the web. config transformations, locate the web. config file in the ASP.NET project, and right-click the item in the solution explorer. Notice the menu item “Add Config Transforms”.

Can we have multiple web config?

There is no restriction to use the web. config file in the asp.net web application. You can have 1 Web. config file per folder .


2 Answers

Scott Gu had an article on this once. The solution he presented was to use a Pre-build event to copy the correct config into place depending on the build configuration chosen.

I also noticed that there already is a similar question here on SO.

like image 65
PHeiberg Avatar answered Sep 19 '22 22:09

PHeiberg


Transforms seem really helpful for this. You can replace certain sections with different rules.

http://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx

like image 22
user1824408 Avatar answered Sep 21 '22 22:09

user1824408