gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 00:43:09 25 4
gpt4 key购买 nike

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

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com