管理大型项目中的配置文件和代码常量

发布于 2024-12-18 15:53:42 字数 254 浏览 4 评论 0原文

我正在开发一个巨大的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱你是孤单的心事 2024-12-25 15:53:42

清理工作会很痛苦;当你继续前进时,你将不得不做很多查找/替换。我首先利用 .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 (or Web.config if an ASP.NET app) and use ConfigurationManager.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 transformations

缺⑴份安定 2024-12-25 15:53:42

ConfigGen 是您祈祷的答案。在 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文