多个AppSettings文件,是可能吗? [英] Multiple AppSettings files, is it possible?

查看:391
本文介绍了多个AppSettings文件,是可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建3个AppSettings配置文件:

I want to create 3 AppSettings config files:


  • Database.config

  • config

  • Global.config

然后在我的App.config中添加:

And after add in my App.config:

<appSettings file="Database.config" />
<appSettings file="Messages.config" />
<appSettings file="Global.config" />

但是当我试图访问一个键,在三个文件之一与 ConfigurationManager 出现以下错误:

But when i try to access a key that there is in one of three files with the ConfigurationManager i got the following error:

配置系统无法初始化。每个配置文件只能显示一次。

Configuration system failed to initialize. Sections must only appear once per config file.

我不能有多个AppSettings配置文件?

I cannot have more than one AppSettings config file?

推荐答案

您不能有多个应用设置,因为它是节的名称。您可以添加一个新的部分,但使用与appsettings相同的部分定义。例如

You can't have more than one appsettings because that's the name of a section. You can add a new section though that uses the same kind of section definition as appsettings. E.g.,

<configuration>
    <configSections>
        <section name="DatabaseConfig" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    </configSections>
    ....
    <DatabaseConfig>
       <add key="Whatever" value="stuff"/>
    </DatabaseConfig>
</configuration>

这篇关于多个AppSettings文件,是可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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