插件使用自己的 app.config [英] Plugin to use its own app.config

查看:19
本文介绍了插件使用自己的 app.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于在一些人的帮助下构建了一个插件架构的工作解决方案,但现在出现了一个新问题.

I finally managed to build a working solution of a plugin architecture with help of some guys over here, but now a new problem arises.

我的托管应用程序使用它的 app.config 文件作为执行程序集(这是一个 Windows 服务)的一些默认值.

My hosting application uses it's app.config file for some defaults for the executing assembly (which is a Windows Service).

每个插件都应该能够从一个单独的插件设置文件加载它自己的设置,因为主机不应该知道插件设置.在插件项目中,我还添加了一个 app.config 文件(带有一些设置和连接字符串),以便我可以实例化 Properties.Settings 类并在插件代码中使用它的属性.

Each plugin should be able to load it's own settings from a separate plugin settings file because the host shouldn't be made aware of the plugin settings. In the plugin project I added an app.config file as well (with some settings and a connection string) so that I can instantiate the Properties.Settings class and use it's properties in the plugin code.

问题是当我更改插件的 app.config 中的设置(构建为 plugin.dll.config)时,我看不到插件本身的这些更改,它仍然使用设计时设置.

The problem is when I change the settings in the app.config of the plugin (which is build as plugin.dll.config) I can't see those changes in the plugin itself, which still uses the design time settings.

有没有办法在每个插件中加载 app.config 设置,以便生成的 Properties.Settings 类可以工作?如果没有,是否有另一种方法将基于 app.config 的设置文件加载到插件中?我计划在 IPlugin 接口中添加 LoadConfiguration 方法,以便每个插件都加载自己的设置.

Is there a way to load the app.config settings in each plugin so the generated Properties.Settings class will work? If not is there another way to load a app.config based settings file into the plugin? I'm planning on adding a LoadConfiguration method in the IPlugin interface so each plugin will load it's own settings.

推荐答案

您正在针对 app.config 的体系结构工作.每个可执行文件(EXE,而不是 DLL)都有一个 app.config 文件.可执行文件启动,创建其 AppDomain,然后加载 MyApp.exe.config.你可以在 Visual Studio 中添加你想要的 app.config 对象,但它们会被 DLL 忽略.我认为您想要做的是从 dll.config 手动复制 XML 并将其粘贴到应用程序级 app.config 中.(我确定有一种方法可以使用 TeamBuild 或类似方法自动执行此操作.)然后覆盖的值将可用于您的 Properties.Settings 类.

You're working against the architecture of app.config. You get one app.config file per executable (EXE, not DLL). The executable launches, creates its AppDomain, and then loads MyApp.exe.config. You can add app.config objects all you want in Visual Studio, but they are ignored for DLLs. I think what you want to do is manually copy the XML from the dll.config and paste it into the application level app.config. (I'm sure there's a way to automate this using TeamBuild or some such.) The overridden values will then be available to your Properties.Settings class.

这篇关于插件使用自己的 app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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