.NET的DLL设置和配置时,有一个Web引用 - 怎么回事? [英] .NET DLL Settings and Config when there's a Web Reference - whats going on?

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

问题描述

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

但在VS2008中,如果添加Web引用到类库(DLL)项目,它增加了一个Settings.Settings文件和app.config文件到项目中。它们包含的Web引用的主URL。

那么,这些文件?有没有办法为DLL读他们求告无门,对吧?

编辑:在app.config的内容,并Settings.Settings似乎有所作为,但:改变(例如)Web引用URL中的DLL项目的app.config文件在自己的没什么区别,但如果你编辑URL中的app.config,然后打开Settings.Settings文件,你的app.config所做的更改,然后被复制到Settings.Settings。然后,该DLL拿起在运行时的新值。它是如何做的呢?

编辑:我在这里的混乱,部分是因为我不是Settings.Settings和App.config中,以及它们如何相互关联之间的差异太清楚,所以也许人们可以协助处理这个问题太

解决方案

有没有办法为DLL读他们,但他们强烈的暗示给消费者的,他们可能想要什么DLL在现实的设置,包括/ config文件

修改

在回应评论由OP - 无论是上编辑的设置会被编译到code作为默认取,如果正确的名称没有设置present在运行时。所以这就是为什么的工作。

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.

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.

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

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?

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.

解决方案

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

Edit

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.

这篇关于.NET的DLL设置和配置时,有一个Web引用 - 怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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