urig
urig

Reputation: 16831

Private web.config for each developer

Consider a group of developers working on an ASP.net web application. Each developer would like to have a private version of the web.config.

By "private" I mean that a developer can freely change the file to suit their dev/test needs at any given moment, without it affecting other team members and without ending up in source control.

How can one go about achieving this with Visual Studio 2015?

My closest solution so far is to have a "private" Solution Configuration with a matching Web.config Transformation file ("web.private.config") that's excluded from source control.

But this is not a satisfactory solution because:

a. The transformation is not run automatically when debugging (with F5). The developers need to remember to run it manually.

b. The result of the transformation ends up in the main "web.config" file which is, naturally, included in source control.

Upvotes: 2

Views: 1880

Answers (4)

Jpsy
Jpsy

Reputation: 20852

We had a very similar problem but only needed personalized versions of the <appSettings> section in Web.config.

In this situation the inclusion of an external file through configSource turned out to be problematic, as this attribute completely replaces the <appSettings>-node. So there remains no way to keep global key/values AND personal key/values for all developers. The whole section is completely replaced by the included private file.

What we need is both global and private <appSettings>. The solution we found was the file attribute. It allows to merge Web.config settings with settings from an additional file.

We ended up with a construct like this one:

<!-- Web.config with global appSettings) -->
...
<appSettings file="Web.PERSONAL.config">
    <add key="BaseUrl" value="https://projectname.dev.local" />
    ...
</appSettings>
...

­

<!-- Web.PERSONAL.config with personal appSettings -->
<?xml version="1.0" encoding="utf-8"?>
<appSettings >
  <add key="EmailSmtpUser" value="[email protected]" />
  <add key="EmailSmtpPwd" value="***" />
</appSettings >

If you put identical keys in both files, the Web.PERSONAL.config version will overwrite the Web.config version.

The file Web.PERSONAL.config must be excluded from Git through .gitignore .

Keep in mind:
While configSource works for ALL nodes in Web.config, the file attribute is restricted to <appSettings>.

Upvotes: 7

Ken Egozi
Ken Egozi

Reputation: 1835

Have web.config include an external file (via configSource) and add that file to .gitignore

Upvotes: 2

tmaj
tmaj

Reputation: 34987

I think there is a lot of value in standardising dev environments so that one can just download the solution and run it.

Custom, long term/permanent, developer specific configs will sooner or later lead to a subtle bug that will be tricky to find.

My solution to your problem would be to find out the reason(s) why permanent individual configs are needed and have a look if these environment specific differences can be eliminated.

Upvotes: 1

Tom Troughton
Tom Troughton

Reputation: 4325

The correct answer is to host your local development site in a separate location from your Visual Studio solution. You can then use publish profiles to publish changes to that location and web.config transforms to maintain a separate local config for each developer. Each developer would use a different publish profile which transforms the web.config with their own transform and deploys the transformed web.config to the publish location. You can then attach a debugger to the published site using Visual Studio's Debug > Attach To Process option.

Upvotes: 1

Related Questions