简体   繁体   English

每个程序集的配置文件

[英]Configuration files per assembly

Is it possible to use the .NET configuration objects to get at .config files specified for a class library assembly rather than the executable assembly. 是否可以使用.NET配置对象获取为类库程序集而不是可执行程序集指定的.config文件。

For example: 例如:

I'm working on a .net port of Concordion and I would like to have options that are specific to Concordion itself but there are also options that are specific to each specification assembly that Concordion calls. 我正在使用Concordion的.net端口,我希望有一些特定于Concordion本身的选项,但也有一些特定于Concordion调用的每个规范程序集的选项。 I would like the Concordion options to be in one .config file while the specification assemblies each have their own .config files (where the schema of each of these config files is the same). 我希望Concordion选项位于一个.config文件中,而规范程序集中每个都有自己的.config文件(其中每个配置文件的架构都相同)。

I can do it right now by writing my own parsing logic but if there is something already built in .NET I would prefer to use that. 我现在可以通过编写自己的解析逻辑来做到这一点,但如果已经在.NET中构建了一些东西,我宁愿使用它。 Right now, as far as I know, it is only possible to have a single .config file for the executable assembly. 现在,据我所知,只有一个.config文件可用于可执行程序集。

You should definitely check out Jon Rista's three-part series on .NET 2.0 configuration up on CodeProject. 你一定要查看Jon Rista关于CodeProject上.NET 2.0配置的三部分系列。

  • Unraveling the mysteries of .NET 2.0 configuration 揭开 .NET 2.0配置的神秘面纱
  • Decoding the mysteries of .NET 2.0 configuration 解码 .NET 2.0配置的奥秘
  • Cracking the mysteries of .NET 2.0 configuration 破解 .NET 2.0配置的奥秘

Highly recommended, well written and extremely helpful! 强烈推荐,写得很好,非常有帮助! He shows how to create and use custom configuration sections, and goes on to explain how to use your own custom.config instead of or in addition to standard .NET config files. 他展示了如何创建和使用自定义配置部分,并继续解释如何使用您自己的custom.config而不是标准.NET配置文件。

Marc

Look at ConfigurationManager.OpenMappedExeConfiguration() . 查看ConfigurationManager.OpenMappedExeConfiguration() It allows you to supply the name of the configuration file you want to open. 它允许您提供要打开的配置文件的名称。 The example there should set you on your way. 那里的例子应该让你顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM