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

查看:116
本文介绍了插件来用自己的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的体系结构。你得到每执行1 app.config文件(EXE,DLL不是)。可执行的推出,创造它的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天全站免登陆