您如何管理大型应用程序的 .NET app.config 文件? [英] How do you manage .NET app.config files for large applications?

查看:17
本文介绍了您如何管理大型应用程序的 .NET app.config 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设一个大型复合应用程序构建在多个基础组件上,这些组件打包在它们自己的程序集中:(数据库读取、协议处理程序等).对于某些部署,这可能包括 20 多个程序集.每个程序集都有设置或配置信息.我们的团队倾向于喜欢 VS 设置编辑器(以及它生成的易于使用的代码!),并且应用程序与用户的区别满足了我们的大部分需求.

Suppose a large composite application built on several foundation components packaged in their own assemblies: (database reading, protocol handlers, etc.). For some deployments, this can include over 20 assemblies. Each of these assemblies has settings or configuration information. Our team tends to like the VS settings editor (and the easy-to-use code it generates!), and the application vs. user distinction meets most of our needs.

但是....

复制和复制很繁琐将许多配置部分粘贴到我们应用程序的 .xml 中.此外,对于跨应用程序往往具有相似配置的共享组件,这意味着我们需要在多个 .config 文件中维护重复的设置.

It is very tedious to copy & paste the many configuration sections into our application's .xml. Furthermore, for shared components that tend to have similar configurations across applications, this means we need to maintain duplicate settings in multiple .config files.

Microsoft 的 EntLib 使用外部工具生成怪物 .config 文件解决了这个问题,但这也感觉很笨拙.

Microsoft's EntLib solves this problem with an external tool to generate the monster .config file, but this feels klunky as well.

您使用什么技术来管理包含来自多个共享程序集的部分的大型 .NET .config 文件?某种包含机制?自定义配置阅读器?

What techniques do you use to manage large .NET .config files with sections from multiple shared assemblies? Some kind of include mechanism? Custom configuration readers?

跟进:

Will 的答案是正是我所得到的,并且对于平面键/值对部分看起来很优雅.有没有办法将这种方法与 自定义结合起来配置部分 ?

Will's answer was exactly what I was getting at, and looks elegant for flat key/value pair sections. Is there a way to combine this approach with custom configuration sections ?

也感谢关于为不同的构建目标管理不同的 .configs 的建议.这也很有用.

Thanks also for the suggestions about managing different .configs for different build targets. That's also quite useful.

戴夫

推荐答案

您使用一个指向其他配置文件的主配置文件.这是一个示例这样做.

You use one master config file that points to other config files. Here's an example of how to do this.

如果链接失效,您要做的是指定 configSource 用于特定的配置部分.这允许您在单独的文件中定义该特定部分.

In case the link rots, what you do is specify the configSource for a particular configuration section. This allows you to define that particular section within a separate file.

<pages configSource="pages.config"/>

这意味着在包含整个 节点树的同一目录中有一个名为pages.config"的文件.

which implies that there is a file called "pages.config" within the same directory that contains the entire <pages /> node tree.

这篇关于您如何管理大型应用程序的 .NET app.config 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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