app.config 中的 appsettings 标签有一个文件属性:
<appSettings file="other.config">
..
..
</appSettings>
这是如何运作的?它会将 appSettings(原始)中的内容与 other.config 文件合并吗?还是会覆盖它?如果 other.config 文件不存在怎么办,它会崩溃吗?
我正在自己尝试,如果 key 不在原始文件中,它似乎不会从 other.config 中读取它?
other.config 文件应该只有 xml 节点,还是应该全部放在 appsettings 元素中?
<appSettings>
<userId>123</userId>
</appSettings>
或
<userId>123</userId>
最佳答案
- 如果文件不存在,它不会崩溃,只是被忽略。
- 外部配置必须包含
<appSettings>
节点,所以你的第一个例子是正确的。 - 外部文件中的值将优先,如果没有值则使用 app.config 值。
这是否涵盖了一切?
关于c# - appsettings 文件属性是否会覆盖 app.config 中的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8990142/