developer specific app.config/web.config files in

2019-01-20 22:47发布

We have several .NET projects where we store certain settings in config files. Now each developer will have their own config files that differ a little (different connection strings to connect to local db, different WCF endpoints etc.)

At the moment we tend to check out app/web.config files and modify them to suit our needs. This leads to many problems since from time to time someone will check in their own settings or loose custom config when getting latest version from tfs.

My question is: how do you deal with situations like this? Or you don't have this problem at all?

9条回答
再贱就再见
2楼-- · 2019-01-20 22:49

One way you could cope is to have a tokenised system and use a rake script to change the values.

A more rudimentary method could be to have a link to an AppSettings.config file for all AppSettings in your web.config (similar with connections) i.e.

<appSettings configSource="_configs/AppSettings.config" />

Then have a folder with each of your developers have a version in a sub folder (i.e. /_configs/dave/). Then when a developer is working on their own code they copy from the sub folder to the root of the linked folder.

You will need to make sure you communicate changes to these files (unless you tokenise). If you keep the AppSettings.config file out of source control and only check in the devs individual folders (all of them) then they will be forced to copy the correct one.

I prefer tokenisation but can be tougher to get up and running if this is only meant to be a quick fix.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-01-20 22:52

We have the same problem and what we are doing is

  • Check in the web.config with testserver / production values
  • Developer goes to windows explorer and change the read only mode of the file
  • Edit the config to suit to their environment.
  • Check in into the web.config happens only when deployment values changes or any config entry is added or deleted.
  • This needs a good amount of comment for each config entry as it needs to be changed by each dev
查看更多
Bombasti
4楼-- · 2019-01-20 22:59

How about ignoring the file, so it never gets checked in? I've run into a similar issue and have added web.config to the ignore list in Subversion.

In TFS though, it's a little bit harder, see this post on how to do it.

查看更多
放荡不羁爱自由
5楼-- · 2019-01-20 23:02

We are using machine.config to avoid having differences in web.config between the environments.

查看更多
Melony?
6楼-- · 2019-01-20 23:07

Assuming you are using Visual Studio, why don't you use different Solution Configurations? For example: you can have a Debug config which uses Web.config.debug and a Release config which uses Web.config.release. Web.config.debug should have something like

<appSettings file="C:/Standard_Path_To_Configs/Standard_Name_For_Config.config"> 

with the file Standard_Name_For_Config.config that gots all the personal developer settings, while the Web.config.release always has the production settings. You can store default configs in some source controlled folder and make a new user take them from there.

查看更多
兄弟一词,经得起流年.
7楼-- · 2019-01-20 23:09

Ignore the files and have a Commom_Web.Config and Common_App.Config. Using a continuous integration build server with build tasks which rename these two to normal names so that the build server can do its job.

查看更多
登录 后发表回答