有 Web 参考时的 .NET DLL 设置和配置 - 发生了什么? [英] .NET DLL Settings and Config when there's a Web Reference - whats going on?

查看:21
本文介绍了有 Web 参考时的 .NET DLL 设置和配置 - 发生了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是,.NET 并没有真正为 DLL做"配置文件——只有主可执行文件或 Web 应用程序获取配置文件,并且可执行文件/Web 应用程序引用的所有 DLL 都从中读取.

My understanding is, that .NET doesn't really 'do' config files for DLLs - only the main Executable or Web App gets a config file, and all DLLs referenced by the Executable/Web App read from that.

但在 VS2008 中,如果您向类库 (DLL) 项目添加 Web 引用,则会向项目添加 Settings.Settings 文件和 app.config 文件.它们包含 Web 参考的主 URL.

But in VS2008, if you add a Web Reference to a Class Library (DLL) project, it adds a Settings.Settings file and an app.config file to the project. They contain the main URL for the Web Reference.

那么这些文件有什么用呢?DLL 无法独立读取它们,对吗?

So what are these files for? There's no way for the DLL to read them unassisted, right?

app.config 和 Settings.Settings 的内容似乎有所不同:更改(例如)DLL 项目的 app.config 文件中的 Web 引用 URL 本身没有区别,但是如果您编辑 app.config 中的 URL,然后打开 Settings.Settings 文件,然后将您在 app.config 中所做的更改复制到 Settings.Settings 中.然后,DLL 在运行时获取新值.这是怎么做到的?

edit: the contents of the app.config and Settings.Settings seem to make a difference though: changing (for example) the Web Reference URL in the DLL Project's app.config file on its own makes no difference, but if you edit the URL in the app.config and then open the Settings.Settings file, the changes you made in app.config then get copied into Settings.Settings. And then, the DLL picks up the new value at run time. How is it doing this?

我的部分困惑是因为我不太清楚 Settings.Settings 和 app.config 之间的区别以及它们之间的关系,所以也许人们也可以帮助解决这个问题.

edit: Part of my confusion here is because I'm not too clear on the difference between Settings.Settings and app.config and how they relate to each other, so maybe people can help out with that issue too.

推荐答案

DLL 无法读取它们,但它们强烈提示您的 DLL 的使用者他们可能希望包含在实际设置中的内容/配置文件

There's no way for the DLL to read them, but they're strong hints to a consumer of your DLL of what they might want to include in the real Settings/Config file

编辑

响应 OP 的评论 - 如果在运行时不存在正确名称的设置,则设置中最后编辑的任何内容都会作为默认值编译到代码中.所以这就是为什么它起作用了.

In response to the comment by OP - Whatever is last edited in the settings gets compiled into the code as a default to take if no setting of the correct name is present at runtime. So that's why that's working.

这篇关于有 Web 参考时的 .NET DLL 设置和配置 - 发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆