且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 SVN 管理开发和生产服务器之间的配置文件差异

更新时间:2022-05-24 22:09:11

一种可能性是将其留给您的构建/部署过程.

One possibility is to leave this up to your build/deploy process.

因此,对于 Web.config,您将在 SVN 中拥有以下内容:Web.config(这可以是你的开发版本)web.config.qa(如果你有qa环境)Web.config.prod

So, for Web.config you would have the following in SVN: Web.config (this can be your development version) Web.config.qa (if you have a qa environment) Web.config.prod

在构建/部署时,您的部署过程知道"它正在部署到什么环境(基于您控制它的方式 - 环境变量、脚本参数等),并在其位置替换正确的配置文件.

At build/deploy time, your deployment process "knows" what environment it is deploying to (based on however you control this - environment variables, script parameters, etc), and substitutes the correct config file in its place.

我更喜欢这种方法,因为它使您的目录和文件结构保持完整(相对于有一个 config 文件夹),并且避免了不必要的分支和合并的麻烦.它确实需要努力确保在进行非特定于环境的更改时更新所有文件,但无论策略如何,您都将为此付出代价.

I prefer this method because it leaves your directory and file structure intact (vs. having a config folder), as well as avoiding unnecessary branches and merging pains. It does require diligence in ensuring that all the files are updated when changes are made that aren't environment specific, but you are going to pay this price regardless of strategy.