c# - 什么是用于加载系统配置属性的 .net 层次结构

标签 c# .net dll .net-3.5 configurationmanager

我有一个一般性问题,但我也会解释为什么要问,以便您更好地理解我的意思。

我有一个 dll,它有一个在设置中定义的 web 服务 url,在运行时它使用 Settings.Default 从设置中获取 url。但是,我们的环境都没有 (dllName).dll.config 文件,并且在调用应用程序的 (exeName).exe.config 中没有定义具体设置。很明显没有使用默认值,因为它设置为某个内部 IP 地址;但这在生产中有效,他们没有在我能找到的任何 .config 文件中定义此设置,并且它仍然以某种方式访问​​正确的 Web 服务 URL。在这种情况下,我需要知道从哪里加载值。

所以我的更广泛的问题是,层次结构如何在 .net 中加载设置?例如,它是否首先查看 machine.config,然后是 (exeName).exe.config,如果它是一个 dll,它会转到 (dllName).dll.config 吗?它首先看哪里,在其他地方看起来是什么顺序,还有没有其他地方我没有提到可以定义这个配置?

此外,对于 DLL,如果您在“设置”中定义了某些内容,它是否会作为默认值嵌入到已编译的 dll 中,如果在任何其他 .config 文件中找不到该属性,是否会使用它?

最佳答案

The hierarchical nature of .NET configuration provides a great level of flexibility, allowing specific users or locations to have their own configuration settings. However, those configuration settings are not isolated and duplicate settings made at a more specific level have the ability to override settings made at a less specific level. As can be seen in picture, the most specific configuration files are merged into the less specific, with the most specific settings overriding the least specific. In the Exe context, User (or to be more precise, Local User) settings are most specific, followed by Roaming User (shared between two or more machines), Application and, finally, Machine.

Config hierarchy and merging

我建议您阅读以下文章,因为您的回答只是引用:

有用的是:

关于c# - 什么是用于加载系统配置属性的 .net 层次结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12114336/

相关文章:

.net - 如何将 dll 导入到在网络服务器上运行的 ASP.NET Web 应用程序中

c# - Web 自动化鼠标点击

c++ - Qt构建为没有dll的单个exe文件

c++ - dllimport 和 dllexport 之间的链接

c# - 删除列表中最后一项时数据绑定(bind)的 InvalidOperationException

c# - 获取转义的多语法 sql 更新字符串

javascript 转义字符串未使用 c# regex.Unescape() 进行转义

c# - 动态 linq 和运算符重载

c# - IronPython:如何访问回溯局部变量

c++ - 调试 .DLL 注入(inject)问题 - 假定执行代码未被命中的断点