MEF 如何解决不位于应用程序根目录的程序集的依赖关系?
我已将应用程序编写为由 win32 MFC 应用程序启动的类库。我的每个视图都是一个单独的程序集,它与基类库一起位于托管 MFC 应用程序的子目录中。
我的问题是,如何让 MEF 使用此子目录而不是根目录中的程序集来解析导出类的依赖关系?
这就是我想要的:
父文件夹 执行程序 子文件夹 myMvvmWindow.dll myMvvmSubWindow.dll *Microsoft.Expression.Interactions.dll*
这是我现在必须拥有的:
父文件夹 执行程序 *Microsoft.Expression.Interactions.dll* 子文件夹 myMvvmWindow.dll myMvvmSubWindow.dll
I have written my application to be a class library that is launched by a win32 MFC application. Each of my views is a separate assembly that is located with the base class library that is located in a sub-directory of the hosted MFC application.
My question is, how can I get MEF to resolve the dependencies of my exported classes using the assemblies from this sub-directory instead of the root directory?
This is what I want:
ParentFolder myapp.exe SubFolder myMvvmWindow.dll myMvvmSubWindow.dll *Microsoft.Expression.Interactions.dll*
This is what I have to have now:
ParentFolder myapp.exe *Microsoft.Expression.Interactions.dll* SubFolder myMvvmWindow.dll myMvvmSubWindow.dll
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以在 app.config 文件中执行此操作:
是否可以在不使用 app.config 的情况下设置程序集探测路径?
这通常是我处理它的方式。
You can also do this in your app.config file:
Is it possible to set assembly probing path w/o app.config?
This is generally how I handle it.
MEF 不会为您处理这种情况,因为它使用 CLR 的正常程序集加载机制来查找依赖项。
但是,您可以通过处理 AppDomain 轻松解决特定子目录的此问题.AssebmlyResolve。如果您检查子文件夹中是否有主目录中无法解析的程序集,您可以自行加载它们并正确执行此功能。
MEF will not handle this scenario for you, as it uses the CLR's normal assembly loading mechanisms to find dependencies.
However, you can easily work around this for a specific subdirectory by handling AppDomain.AssebmlyResolve. If you check your sub folder for the assemblies that don't resolve in your main directory, you can load them yourself and make this function properly.