Reputation: 16831
Consider a bunch of developers working on an ASP.net web application. Each dev has a private copy of the DB, running on their private, local DB engine so each dev has a different connection string.
Currently, each dev has web.config modified with their connection string and occasionally one of these modifications gets committed to source control, which is not good.
How can I both have a default web.config in source control and let each dev have their own private copy that is ignored by source control? (I would prefer a solution that avoids web.config transformation files if possible, as their syntax is a bit opaque).
Upvotes: 3
Views: 107
Reputation: 1932
In our projects I've set things up so that there the default configuration is under source control as web.config.template
and the web.config
itself is ignored. Developers then simply copy web.config.template
as web.config
; and make any local edits they need.
It's simple enough to be a manual thing, but it is also possible to use MSBuild to automate the copy (only copying if web.config
doesn't already exist).
If you have a CI/build server then you may want to also take the approach that web.config.template contains the configuration for use in the CI build - that way your CI build is simplified as it can always just overwrite web.config
with web.config.template
.
Upvotes: 1
Reputation: 714
There are a couple of things that can help.
Enforce convention that is followed by all developers. For instance, Sql Server instance name, database name etc should be same on all developers machines so that you don't need to change them. Also any file location kind of settings should always be respective to the project or some system location. Overall the idea is to keep your settings so that developers need not checkout and change anything.
In some cases, enforcing the above might not be possible. In that scenario, you can move those changing settings to a different file and refer that in your web.config using 'configSource'. Then developers can change that settings file as per their local machine environment. Also in that case you would like to ensure that not everybody in the team can checkin that file so that to prevent unwanted overriding.
Hope it helps.
Upvotes: 1