Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing web.config files

I have 3 environments: Dev, QA, Prod on .NET 4. Each has a unique web.config file. We have been having problems managing all three versions. Its easy to overlook something critical when manually merging web.config files in TFS. More than once we have ended up with a connection string pointing to QA on Prod.

So, I read up on web.config transformations. These appear to require MSBUILD. We have no build server so I'm not sure how I can attempt to use this solution. Is there a way to make transformations work with a normal web publish?

Do you have any alternative suggestions for managing 3 web.config files?

like image 640
P.Brian.Mackey Avatar asked Jul 08 '11 13:07

P.Brian.Mackey


People also ask

What are Web config files?

A web. config file is a Windows file that lets you customize the way your site or a specific directory on your site behaves. For example, if you place a web. config file in your root directory, it will affect your entire site (www.coolexample.com).

Can we have 2 Web config files?

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.


2 Answers

Is there a way to make transformations work with a normal web publish?

Absolutely, take a look at this MSDN link. You do not need MSBUILD. You can set your connection strings for your various environments in separate config files. For example, you could have Web.config, Web.QA.config, and Web.Prod.config, where QA and Prod are separate Visual Studio Build configurations.

Alternatively, you could just use the build configurations that are added by default: Web.config (local development), Web.Debug.config (use for QA), and Web.Release.config (use for production).

Using this setup as an example, Web.config would have all configuration, Web.Debug.config would have only the config that changes for that environment (connection strings, app settings, etc), and Web.Release.config has only the config that changes for that environment.

Once your configs and transformations are setup, you just change your build configuration, build and publish from Visual Studio.

like image 131
BrandonZeider Avatar answered Nov 11 '22 17:11

BrandonZeider


Do you have any alternative suggestions for managing 3 web.config files?

Yes, don't manage them. The less we manage, the less chances of making mistakes. Have exactly the same web.config files for all your environments. Same distributive package deployed everywhere.

And all environment specific keys such as base urls, connection strings, ... could be defined in machine.config which you deploy only once on each server and reused from all your applications. Or a web.config at the root of your IIS site which all applications would derive from.

like image 42
Darin Dimitrov Avatar answered Nov 11 '22 15:11

Darin Dimitrov