管理大型项目中的配置文件和代码常量
我正在开发一个巨大的 C# 代码库(~300 KLOC)。系统的组件使用分散在文件夹层次结构中的配置文件。从一个位置的配置读取的值存储在另一个位置的常量中。在不同的文件夹中存在相同配置的多个副本,复制并签入一次,然后从未更新。有些文件有 3 个不同的版本,一种用于开发人员计算机,一种用于暂存,另一种用于实时系统。我必须清理这个可怕的烂摊子。我应该如何开始?处理不同文件中的重复值、同一文件的多个副本以及不同构建环境的多个版本的智能策略是什么?如何将所有内容存储在一个地方而不创建“依赖磁铁”?
I'm working on a huge C# codebase (~300 KLOC). The components of the system use config files scattered across the folder hierarchy. Values that are read from config in one place are stored in a constant in another. There are several copies of the same config in different folders, copied and checked in once, and then never updated. Some files have 3 different versions, one for the developer machine, one for staging and another one for the live system. I have to clean up this horrible mess. How should I start? What is an intelligent strategy to deal with duplicated values in different files, multiple copies of the same file and multiple versions for different build environments? How can I store everything in one place without creating a "dependency magnet"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
清理工作会很痛苦;当你继续前进时,你将不得不做很多查找/替换。我首先利用 .NET 已经提供的功能,即将所有这些设置放在
Application.config
上(如果是 ASP.NET 应用程序,则放在Web.config
上),然后使用ConfigurationManager.AppSettings["key"]
检索各种值。至于不同的环境,也有开箱即用的支持,您可以使用 appSettings 转换The clean up is going be painful; you'll have to do a lot of find/replace as you move along. I'd start by leveraging what .NET already offers, which is, put all these settings on
Application.config
(orWeb.config
if an ASP.NET app) and useConfigurationManager.AppSettings["key"]
to retrieve the various values. As far as the different environments, there's also support for this out of the box, you can use appSettings transformationsConfigGen 是您祈祷的答案。在 CodePlex 上查看: ConfigGen
它完全符合您的要求。
更新:
看看我的使用示例: 如何为多个构建配置选择不同的app.config
The answer to your prayers is ConfigGen. Check it out on CodePlex: ConfigGen
It does exactly what you are asking for.
Update:
Look at my examples of usage here: How to select different app.config for several build configurations