将app.config的一部分移动到单独的文件中

时间:2009-05-18 11:35:24

标签: .net configuration app-config

为了方便我的应用程序,我需要在单独的文件中使用app.config的“runtime”元素。

尝试了类似

的内容
<runtime file="runtime.conf" />

以及

<runtime configFile="runtime.conf" />

在runtime.conf中我有:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
            .......
    </assemblyBinding>
</runtime>

但它被忽略了......

有没有办法找出问题所在。

当然,当我将运行时部分直接复制到app.config时,它可以工作。

我在某处发现,当使用configFile =“...”时,包含的文件必须位于子目录中。试了但是它也行不通......

似乎包括不适用于运行时部分。

4 个答案:

答案 0 :(得分:2)

嗨,您的runtime.conf位于应用程序的bin文件夹中

答案 1 :(得分:2)

您无法使用configSource外部化&lt; runtime&gt;配置。

&LT;运行时间&GT;是一种特殊情况,它不会读取configSource中指定的任何外部文件中的值。

指定“configSource”属性不会导致错误,不会读取源文件。

此处提供更多信息:http://world.episerver.com/Blogs/Magnus-Rahl/Dates/2011/6/Todays-gotcha-configSource-on-the-runtime-section-element/

答案 2 :(得分:1)

试试这个:

<runtime configSource="runtime.conf"/>

答案 3 :(得分:0)

您可以使用linkedConfiguration元素https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/linkedconfiguration-element

从外部文件加载绑定重定向配置
<configuration>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <linkedConfiguration href="file://c:\Program Files\Contoso\sharedConfig.xml"/>
  </assemblyBinding>
</configuration>