How can I let each developer have their own, private, web.config?

Consider a group of developers working in an ASP.net web application. Each developer has a private copy of the database running on their private local database, so each developer has a different connection string.

Nowadays every developer has a web.config modified with their connection string, and sometimes one of those modifications gets bound to source control, which is not good.

How can I use the default web.config file in the source control and let each developer have their own personal copy, ignored by the source code? (I would prefer a solution that avoids the web.config transform files if possible, since their syntax is a bit opaque).

+3


source to share


2 answers


There are several things that can help.

  • Forced agreement that all developers follow. For example, Sql Server Instance Name, Database Name, etc. Should be the same on all development machines, so you don't need to change them. Also any type of file location must always correspond to a project or some system location. In general, the idea is to keep your settings so developers don't have to check and change anything.

  • In some cases, the above may not be possible. In this case, you can transfer these changes to another file and reference this in your web.config using "configSource". Developers can then modify this settings file to suit their local machine environment. Also in this case, you would like to make sure that not everyone on the team can check this file to prevent unwanted overrides.



Hope it helps.

+1


source


In our projects, I set everything so that the default configuration is controlled by the source as web.config.template

, and itself is web.config

ignored. Then the developers just copy web.config.template

like web.config

; and make any local changes they need.

It's easy enough to be manual, but you can also use MSBuild to automate the copy (copy only if web.config

doesn't already exist).



If you have a CI / build server, you might also want the approach that web.config.template contains the configuration to use in the CI build - this way your CI build is simplified as it can always just overwrite web.config

with web.config.template

.

+1


source







All Articles