从另一个文件加载部分 App.Config [英] Load parts of App.Config from another file
问题描述
我喜欢将我的 app.config
分成用户特定部分和应用程序特定部分.是否可以将 app.config
的一部分存储在另一个文件中?
I like to split my app.config
into a user specific part and an application specific part. Is it possible to store a part of the app.config
in another file?
我已经试过了:
<!DOCTYPE cruisecontrol [<!ENTITY email SYSTEM "email.config">] >
但这不会加载.
在不改变应用程序本身的情况下还有其他可能吗?
Is there another possiblity without changing the application itself?
推荐答案
您可以使用 configSource
属性告诉框架从另一个文件加载特定部分.
You can use the configSource
attribute to tell the framework to load a particular section from another file.
例如,如果您有一个包含如下部分的配置文件:
For example, if you had a config file with a section like this:
<connectionStrings>
<add name="MyDatabase" connectionString="...etc..." />
</connectionStrings>
您可以将其替换为:
<connectionStrings configSource="ConnectionStrings.config" />
...并使用原始部分的内容(包括
节点 - 与我的第一个代码完全相同)创建一个文件 ConnectionStrings.config
以上部分).
...and create a file ConnectionStrings.config
with the contents of the original section (including the <connectionStrings>
node - exactly the same as my first code section above).
这篇关于从另一个文件加载部分 App.Config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!