c# - appsettings 文件属性是否会覆盖 app.config 中的内容?

标签 c# asp.net visual-studio web-config

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/

相关文章:

c# - 通过 LINQ to SQL 中的新对象更新实体

ASP.NET 4.0 数据库创建的页面

visual-studio - 多个构建配置可以共享一个配置转换吗?

.net - 如何将属性选项卡添加到 Visual Studio 2019 中的类库项目?

c# - 找不到 ASP.NET 5.0 中的 HttpClient?

c# - 将组件列表解析为构造函数参数

c# - Razor View 引擎 - 如何添加部分 View

c# - 遍历控件时如何设置Dropdownlist特定属性?

c# - 如何使用 ASP.NET 反序列化 JavaScript 数组

c - Visual Studio "illegal use of this type as an expression"