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

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

问题描述

我们在不同的办公室有多个开发团队,他们需要为我们项目的web.configapp.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.

我们喜欢使用一组合理的默认值来检查这些配置文件,这样通过检查主干/主分支,您就可以在不需要四处寻找配置文件的情况下工作.

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 的自动 ignore-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 实际配置文件:这是推荐的,例如,在 这个答案.我看到的主要问题是对配置文件的更改很容易被遗忘,在两个不同的点:提交者很容易错过他们需要添加到 .sample 文件的更改,以及消费者(esp. 持续集成服务器)很容易错过他们需要从 .sample 文件合并到本地配置文件的更改.所以基本上,这似乎不是一个很好的解决方案.

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 配置文件,覆盖它定义的任何设置:这是提供的,例如,此处.问题在于我们正在使用标准的 .Net 配置提供程序 - 当 Mirosoft 已经完成所有工作时,我真的不希望我们实施全新的设置加载框架.有谁知道获取 app.config 和 web.config 文件以引用可选本地覆盖文件的方法吗?

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:让开发人员保留本地分支,然后让他们始终将挑选出来的分支或重新定位的分支签入主分支,以始终绕过/避免其本地分支中不需要的提交:这是在此处提供了一个可能的工作流程,虽然我很欣赏它在更改跟踪方面的清洁度(所有已签入的内容),它会在每次签入时引入大量必需开销;这是一个很大的痛苦!

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:签入配置文件,但将它们标记为 --assume-unchanged:这是一个可能的选项 这里;据我所知,它在精神上与 TortoiseSVN 中的 ignore-on-commit 更改列表非常相似,除了在提交过程中您无法看到这些隐藏"更改的文件;例如,TortoiseGit 确实显示带有已更改"图标覆盖的文件,但在提交对话框中该文件根本不显示.这看起来有点吓人,而且很容易忘记检查更改.

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,所以配置转换不可用.

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

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

更新 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天全站免登陆