有没有办法使用configSource在配置文件中包含多个层次结构?

时间:2011-12-20 23:08:06

标签: .net configuration app-config configsource

我想知道在以下结构中是否有方法或解决方法来配置文件:

App.Config中

<configuration>
  <appSettings configSource="AppSett.config">
    <add key="test1" value="test2"/>
  </appSettings>
</configuration>

我的 AppSett.config 将如下所示:

<appSettings>
  <add key="test3" value="test3"></add>
</appSettings>

3 个答案:

答案 0 :(得分:3)

不,您不能使用部分信息的外部文件来链接而不是默认的配置结构。配置文件是符合配置架构的特殊文件,您无法在所描述的场景中使用它们。

答案 1 :(得分:1)

是的,这就是configSource的用途,但配置部分可以包含content或configSource属性,而不是两者。

答案 2 :(得分:0)

您可以使用file属性而不是configSource来实现此方法:

在您的示例中,您应该有文件App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings configSource="AppSett.config">
    <add key="test1" value="test2"/>
  </appSettings>
</configuration>

AppSett.config

<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
  <add key="test3" value="test3"></add>
</appSettings>