问题描述
我们有我们存储在配置文件中的某些设置几个.NET项目。
现在每个开发人员将有不同的一点自己的配置文件(不同的连接字符串来连接到本地数据库,不同的WCF终端等)
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.)
目前,我们倾向于检查出的应用程序/ web.config文件中,并修改它们来满足我们的需要。
这导致了许多问题,因为不时从TFS获取最新版本时,有人会检查自己的设置或松散的自定义配置。
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?
推荐答案
我们使用结合了多种在此页面上已有答案,再加上借鉴了<的系统href=\"http://www.hanselman.com/blog/managingmultipleconfigurationfileenvironmentswith$p$pbuildevents.aspx\">this由Scott Hanselman的建议。
We use a system that combines several of the existing answers on this page, plus draws on this suggestion by Scott Hanselman.
总之,我们所做的就是有一个共同的app.config / web.config中,并有大部分是在单个文件的具体设置,由其他的答案这里建议。例如我们的SMTP设置,在app.config包含
In short, what we did was to have a common app.config / web.config, and to have most of the specific settings in individual files, as suggested by other answers here. e.g. for our SMTP settings, the app.config contains
<system.net>
<mailSettings>
<smtp configSource="config\smtp.config" />
</mailSettings>
</system.net>
此文件的是源代码控制。但是,单个文件,像这样的,不是:
This file is in source control. However, the individual files, like this, are not:
<?xml version="1.0" encoding="utf-8" ?>
<smtp deliveryMethod="Network">
<network host="127.0.0.1" port="25" defaultCredentials="false" password="" userName ="" />
</smtp>
这不是相当,其中故事的结局虽然。什么新的开发商,还是一个新的源安装?配置的大头不再是源头控制,这是一个痛苦的手工打造他们需要的所有的.config文件。我preFER有来源,至少会编译开箱的。
That's not quite where the story ends though. What about new developers, or a fresh source installation? The bulk of the configuration is no longer in source control, and it's a pain to manually build all of the .config files they need. I prefer to have source that will at least compile right out of the box.
因此,我们做保持版的.config文件的源代码控制,名为 .config.default 文件。因此,一个新的源代码树看起来是这样的:
Therefore we do keep a version of the .config files in source control, named .config.default files. A fresh source tree therefore looks like this:
不过,不是真的任何使用开发者,因为到Visual Studio,他们只是毫无意义的文本文件。因此,批处理文件, copy_default_config.bat
,需要从.config.default文件创建一组初始的.config文件的护理:
Still, not really any use to the developer, since to Visual Studio they're just meaningless text files. Hence the batch file, copy_default_config.bat
, takes care of creating an initial set of .config files from the .config.default files:
@echo off
@REM Makes copies of all .default files without the .default extension, only if it doesn't already exist. Does the same recursively through all child folders.
for /r %%f in (*.default) do (
if not exist "%%~pnf" (echo Copying %%~pnf.default to %%~pnf & copy "%%f" "%%~pnf" /y)
)
echo Done.
该脚本安全地重新运行的,在开发商谁已经有自己的.config文件将不会有他们的覆盖。因此,人们可以想见,运行该批处理文件为pre-生成事件。在.DEFAULT文件中的值可能不完全正确的一个新的安装,但他们是一个合理的起点。
The script is safely re-runnable, in that developers who already have their .config files will not have them overwritten. Therefore, one could conceivably run this batch file as a pre-build event. The values in the .default files may not be exactly correct for a new install, but they're a reasonable starting point.
最后每一个开发者与最终是看起来像这样的配置文件的文件夹:
Ultimately what each developer ends up with is a folder of config files that looks something like this:
这似乎有点令人费解,但它肯定preferable给开发踩着对方的脚趾的麻烦。
It may seem a little convoluted, but it's definitely preferable to the hassle of developers stepping on each other's toes.
这篇关于开发商具体的app.config /在Visual Studio中web.config文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!