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

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

问题描述

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

I want to create 3 AppSettings config files:

  • Database.config
  • Messages.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,因为这是一个节的名称。您可以添加新的一节,虽然使用相同类型的部分定义的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>

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

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