app.config中的appsettings标记具有文件属性:
<appSettings file="other.config">
..
..
</appSettings>
这是如何运作的?它会将appSettings(原始)中的内容与other.config文件合并吗?或者它会覆盖它吗?如果other.config文件不存在,该怎么办呢?
我自己尝试,如果一个键不在原来的,它似乎不是从other.config读取它?
other.config文件应该只有xml节点,还是应该都在appsettings元素中?
<appSettings>
<userId>123</userId>
</appSettings>
要么
<userId>123</userId>
<appSettings>
节点,因此您的第一个示例是正确的。这会掩盖一切吗?
关于这个问题的最佳答案之一是:ASP.NET web.config: configSource vs. file attributes - 来自@Massimiliano Peluso
file
属性
appSettings
部分.config
.Configuration调用中合并回主Save。configSource
属性
appSettings
configSource
.Configuration调用中将所有设置添加到Save中指定的文件中。System.Configuration.ConfigurationErrorsException
。file
属性指定包含自定义设置的外部文件,就像在web.config文件的appSettings条目中一样。同时,configSource
属性中指定的外部文件包含您声明configSource的部分的设置。例如,如果使用pages部分的configSource属性,则外部文件将包含pages部分的设置。
在file属性中指定的外部配置中声明的自定义设置将与web.config文件中appSettings部分中的设置合并。同时,configSource不支持合并,这意味着您必须将整个部分设置移动到外部文件中。
http://www.codeproject.com/Messages/1463547/Re-difference-between-configSource-and-file-attrib.aspx