在解决方案中将 MEF 与多个项目结合使用
我有一个具有以下结构的解决方案:
解决方案
<块引用>主执行程序
实用程序
当我在实用程序项目中使用 MEF 时,我发现以下 MEF 目录都无法获取 Main Exe 中保存的类型,
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
catalog.Catalogs.Add(new DirectoryCatalog(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory)));
我假设第一个在实用程序项目中调用时失败,而第二个由于类型而失败主项目中的内容存储在 EXE 而不是 DLL 中...
获取可查找解决方案的所有项目中的所有类型的 Mef 目录的正确方法是什么?
I have a solution with the following structure:
Solution
Main Exe
Utilities
When I use MEF within the Utilities project I find that neither of the following MEF catalogues pick up types held within the Main Exe
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
catalog.Catalogs.Add(new DirectoryCatalog(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory)));
i assume the first fails as its being called within the utilities project, and that the second fails since the types in the main project are stored in an EXE and not a DLL...
what is the correct way to get a Mef catalogue which finds all types in all the projects of a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我的项目中,我只需在构建后事件中放置一个命令,该命令将输出复制到主应用程序 bin 目录中:
然后我只需从根目录路径加载:
In my projects I simply put a command in the post-build events, which copies the output into the main apps bin directory:
Then I just load from the root directory path:
刚刚发现 Assembly.GetEntryAssembly() 因此以下内容将起作用
,尽管它不会加载解决方案中的其他类型 - 一种选择是使用目录目录,但我想知道是否有某种方法可以避免使用它,因为它增加了可能性在我不立即需要的地方引入第三方类型?
Just Spotted Assembly.GetEntryAssembly() so the following will work
although it does not load the other types in the solution - one option is to use a Directory catalogue though i wonder if there is some way to avoid using this as it raises the possibility of introducing 3rd party types where i dont immediatly want them?