[英]How to organize a modular (C#/MEF) application in Visual Studio to allow debugging?
I am in the process of developing a modular application using C# and MEF. 我正在使用C#和MEF开发模块化应用程序。 The application is supposed to consist of
该应用程序应包含
The main application may either run all by itself or with one or more plug-ins imported. 主应用程序可以全部运行,也可以导入一个或多个插件。 This should be a rather standard architecture for a modular MEF-based application.
对于基于模块化MEF的应用程序,这应该是一个相当标准的体系结构。 Initial tests have shown that this appears to generally work.
初步测试表明,这似乎普遍有效。 If I deploy the main application as well as one or multiple plug-in assemblies in to a folder, everything works fine.
如果我将主应用程序以及一个或多个插件程序集部署到一个文件夹中,则一切正常。
However, I am struggling with how to organize the Visual Studio solution for this. 但是,我正在为如何组织Visual Studio解决方案而苦苦挣扎。 My initial approach is that the main application, as well as each plug-in are separate projects within a solution.
我最初的方法是主应用程序以及每个插件都是解决方案中的独立项目。 The main application is an exe project, whereas the plug-ins are dll projects.
主要应用程序是一个exe项目,而插件是dll项目。 Plug-in projects depend on the main project, since they are implementing interfaces and using classes defined in the main application (I could have created a common lib project that does this, but it does not seem to add any benefit).
插件项目依赖于主项目,因为它们正在实现接口并使用在主应用程序中定义的类(我本可以创建一个通用的lib项目来执行此操作,但似乎没有任何好处)。
This way, I can start and debug the main application (with no plug-ins) fine. 这样,我可以很好地启动和调试主应用程序(没有插件)。
But how can the solution be organized so I can debug the main application with one, multiple or all plug-ins? 但是如何组织解决方案,以便我可以使用一个,多个或所有插件调试主应用程序? The current approach builds each plug-in into its own folder (which is generally fine) and copies the main application into each of these (which is not quite desirable).
当前的方法是将每个插件构建到自己的文件夹中(通常很好),然后将主应用程序复制到其中的每个应用程序中(不太理想)。 I could potentially configure an individual plug-in project to start the main application in its output folder, but I have no idea how to do this for more than one plug-in or how to do this if the main application should not be copied into each plug-in output folder.
我可能会配置一个单独的插件项目,以在其输出文件夹中启动主应用程序,但是我不知道如何对多个插件执行此操作,或者如果不应将主应用程序复制到该插件中,该怎么做每个插件输出文件夹。
Any hints or best practices would be highly appreciated. 任何提示或最佳做法将不胜感激。 I am using Visual Studio 2015 - if that makes any difference.
我正在使用Visual Studio 2015-如果有什么不同。
Plug-in projects depend on the main project, since they are implementing interfaces and using classes defined in the main application (I could have created a common lib project that does this, but it does not seem to add any benefit).
插件项目依赖于主项目,因为它们正在实现接口并使用在主应用程序中定义的类(我本可以创建一个通用的lib项目来执行此操作,但似乎没有任何好处)。
There are benefits to it, here's a couple of them: 它有很多好处,有几个:
But how can the solution be organized so I can debug the main application with one, multiple or all plug-ins?
但是如何组织解决方案,以便我可以使用一个,多个或所有插件调试主应用程序?
Typcially you tell your main application at startup which plugins to load. 通常,您在启动时告诉主应用程序要加载哪些插件。 There are different ways to do this: read a file containing names of plugins, scan a known directory for plugins, a combination.
有多种方法可以执行此操作:读取包含插件名称的文件,扫描已知目录中的插件,以及两者的结合。 All supported or relatively easy to implement using MEF.
所有都支持或相对容易使用MEF实施。 For instance for one large C# app we have, all plugins are copied into something like bin\\Plugins.
例如,对于我们拥有的一个大型C#应用程序,所有插件都被复制到bin \\ Plugins之类的文件中。 When the application starts it looks for dlls in bin\\Plugins, filters the list based on a textfile containing regexes, then loads plugins from the filtered list.
当应用程序启动时,它将在bin \\ Plugins中查找dll,根据包含正则表达式的文本文件过滤列表,然后从过滤后的列表中加载插件。 When sending the application to customers they get all, or only some plugins.
将应用程序发送给客户时,他们可以获得全部或仅一些插件。 When developping we use the text file to cut down application load time.
开发时,我们使用文本文件来减少应用程序的加载时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.