git中的web.config和app.config机器特定设置 [英] web.config and app.config machine-specific settings in git

查看:88
本文介绍了git中的web.config和app.config机器特定设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在不同的办公室中拥有多个开发人员团队,他们需要在我们项目的 web.config app.config 文件中为多个配置设置使用不同的值

We have multiple teams of developers in different offices, and they need different values for a number of configuration setting in our projects' web.config and app.config files.

我们希望使用一组明智的默认值来使这些配置文件保持签入状态,以便通过检出trunk/master分支,您可以进行某些工作而无需深入研究配置文件.

We like to keep these configuration files checked in with a sensible set of default values, so that by checking out the trunk/master branch you have something working without needing to dig around for configuration files.

从历史上看,我们使用了Subversion,尤其是TortoiseSVN,这为管理本地更改提供了一种简便的方法:我们只需将这些文件添加到TortoiseSVN的自动 commitre-on-commit 更改列表中即可.这样可以防止意外检入这些文件,因为您随后需要专门选择它们以将它们包括在检入中(并且可以确保检入的是重要更改,而不是本地配置噪声).这种方法的主要缺点是配置文件总是看起来已更改",因此无法一目了然地知道您是否进行了任何本地更改.

Historically we've used Subversion, and specifically TortoiseSVN, and this provided an easy way to manage local changes: We simply added these files to TortoiseSVN's automatic ignore-on-commit changelist. This prevents accidental checkin of these files, as you then need to select them specifically to include them on a checkin (and you can make sure you're checking in significant changes, not local-config noise). The main disadvantage of this approach is that the config files always look "changed", so it's not possible to at-a-glance know whether you have any local changes.

我们正在寻求切换到Git,我正在尝试找出最佳方法.

We're looking to switch to Git, and I'm trying to figure out the best approach.

首先,其他StackOverflow答案中已经存在的内容:

First off, what's already there in other StackOverflow answers:

选项1:检入xxx.sample文件并.gitignore实际的配置文件:建议在例如

Option 1: Check in xxx.sample files and .gitignore the actual config files: This is recommended, for example, in this answer. The main problem I see with this is that changes to the config file are easily forgotten, at two different points: The committer can easily miss changes that they need to add to the .sample file, and consumers (esp. continuous integration server) can easily miss changes that they need to incorporate from the .sample file into their local config file. So basically, that doesn't seem like a very good solution.

选项2:有一个签入的xxx.defaults文件和一个.gitignored xxx.local配置文件,该文件将覆盖其定义的所有设置:例如,

Option 2: Have a checked-in xxx.defaults file and a .gitignored xxx.local config file which overrides any settings it defines: This is offered up, fr example, here. The issue there is that we're working with standard .Net configuration providers - I really don't want us to implement a whole new settings-loading framework when Mirosoft's already done all the work. Does anyone know a way to get app.config and web.config files to refer to optional local override files?

选项3:让开发人员保留本地分支,然后让他们始终将樱桃小树枝或重新建立基础的分支检入master,以始终绕过/避免在其本地分支中进行不需要的提交:这是在此处中作为可能的工作流提供,尽管我很欣赏它在变更跟踪方面的整洁(一切都已签入),因此每次签入都会产生大量 required 开销;这是一个很大的痛苦!

Option 3: Have developers keep local branches, and then have them always check in cherry-picks or rebased branches into master, to always bypass/avoid the unwanted commits in their local branch: This is offered as a possible workflow here, and while I appreciate the cleanliness of it in terms of change-tracking (everything checked in), it introduces a significant amount of required overhead on every single checkin; it's a major pain!

选项4:检入配置文件,但将其标记为-假定未更改 :这是可能的选项

Option 4: Have config files checked in, but have them marked with --assume-unchanged: This is offered as a possible option here; as far as I can tell it's very similar in spirit to the ignore-on-commit changelist in TortoiseSVN, except you have no visibility to these "hidden" changed files in a commit process; TortoiseGit, for example, does show the file with a "changed" icon overlay, but in the commit dialog the file does not show up at all. This seems a little frightening, again very easy to forget to check changes in.

鉴于这些选项,这些都是我发现的选项,我真的很希望找到一种方法,可以选择将本地配置文件包含"在已签入的app.config/web.config文件中/之上.使用选项2 ;有谁知道这样做的方法,或者我所缺少的其他选择?(我很想考虑一个自定义的Xml合并预构建步骤...)

Given these options, which are all the ones I've found, I'm really hoping for a way to optionally "include" a local config file into/over a checked-in app.config/web.config file and go with option 2; does anyone know of a way to do this, or other options that I'm missing? (I'm faintly tempted to consider a custom Xml-merging pre-build step...)

我应该早先提到过,我们仍在VS2008上,因此不提供Configuration Transforms.

I should have mentioned earlier, we're still on VS2008, so Configuration Transforms are not available.

更新 :(已删除,是完全错误的)

UPDATE: (deleted, was plain wrong)

更新2:我已经删除了以前的更新并回答,这很愚蠢/无法正常工作.我没有意识到在我们的"合并之后,另一个方向的下一次合并会将这些文件的原始"版本带回(覆盖了本地分支更改).如果有兴趣,请参阅编辑历史记录.这个问题一如既往.

UPDATE 2: I've deleted my previous update and answer, it was stupid / didn't work. I didn't realize that after an "ours" merge, the next merge in the other direction carries the "original" versions of those files back (overwrites the local branch changes); see edit history if you're interested. This question is as open as ever.

推荐答案

我建议您查看 ConfigGen.我们在所有项目中都使用它,它为所有开发人员和所有环境带来了奇迹.它基本上从一个电子表格开始,该电子表格指出机器名称和输出配置文件,然后标记一个模板App.Config或Web.Config,将电子表格中的值替换为它.在您的项目中添加一个简单的预构建步骤以运行configgen,然后在构建开始之前,为您的计算机量身定制一个配置文件.它还支持默认设置.

I'd like to suggest you look at ConfigGen. We use it in all our projects, and it works wonders for all the developers and also for all our environments. It basically runs off a spreadsheet that states machine name and output configuration file, and then tokenises a template App.Config or Web.Config, substituting values from the spreadsheet into it. Add a simple pre-build step to your projects to run configgen, and before the build kicks off, you have a tailored configuration file for your machine. It also supports default settings.

看看这个网站并下定决心,但我绝对可以保证.

Take a look at the site and make your own mind up, but I can definitely vouch for it.

编辑:值得注意的是,您随后可以忽略所有Web.config和App.config文件(以.git表示).但是您确实需要将模板和电子表格添加到存储库中.另外,我确信有一种方法的更新,很可能包括电子表格的xml替换,它具有自己的编辑器,非常适合DVCS.

EDIT: It's worth noting that you can then ignore all your Web.config and App.config files (in terms of .git). But you do need to add your templates and spreadsheets to the repo. Also, I am assured there is an update on the way that may well include an xml replacement for the spreadsheets, that has it's own editor, making it eminently more suitable for DVCS's.

Edit2 :也可以在此处查看Daniel的帖子: https://stackoverflow.com/a/8082937/186184 .他给出了一个非常清晰的模板和电子表格示例,以及如何使其在您的解决方案中正常工作.

Edit2: Also take a look at Daniel's post here: https://stackoverflow.com/a/8082937/186184. He gives a very clear example of the template and spreadsheet, and how to get it working in your solution.

这篇关于git中的web.config和app.config机器特定设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆