检查.NET Core中动态加载的库的依赖关系 [英] Inspect dependencies for dynamically loaded library in .net core

查看:377
本文介绍了检查.NET Core中动态加载的库的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建使用来自外部dll-s的某些功能的插件. 因为我不知道将使用哪个插件,所以我想动态加载:

I'm trying to create plugin which uses some functions from external dll-s. Because I don't know which plugin will be used I would like to dynamically load:

  1. 主要asp.net核心项目,该项目使用反射功能动态加载诸如mailservice.dll之类的插件.

  1. main asp.net core project which dynamically loads plugins like mailservice.dll using reflection.

mailservice.dll库,该库公开CheckMail()方法(我使用MimeKit作为IMAP助手).

mailservice.dll library which exposes CheckMail() method (I use MimeKit as a IMAP helper).

一切正常,但是当我调用CheckMail()方法时,我收到 System.IO.FileNotFoundException:无法加载文件或程序集'MailKit,版本= 1.16.0.0 . 因此,我把从发行版中提取的MimeKit的所有依赖项放了进去,仍然没有(46个文件). 当我使用nuget将MimeKit软件包安装到我的主asp.net项目中时,一切运行正常,但显然我不想保留这种依赖性.

Everything loads fine but when I invoke CheckMail() method I receive System.IO.FileNotFoundException: Could not load file or assembly 'MailKit, Version=1.16.0.0. So I put all dependencies for MimeKit extracted from release version and still nothing (46 files). When I install MimeKit package using nuget to my main asp.net project everything runs fine but obviously I don't want keep such dependency.

是否有工具或技术来检查丢失的文件?

Is there any tool or technique to inspect which file is missing?

推荐答案

要从dotnet核心主机获取程序集探测路径,可以启用核心主机跟踪.
如果您是从Visual Studio运行,请转到命令提示符和asp.net核心主要解决方案的位置

To get assembly probing path from the dotnet core host,you can enable core host tracing.
If you are running from Visual Studio, Go to command prompt and location of your asp.net core main solution

首先使用此命令设置环境变量

set the environment variable with this command first

set COREHOST_TRACE=1

之后,只需使用 dotnet run 运行,您将获得完整的详细信息

After that just run using dotnet run and you will get full details

要将输出重定向到文本文件,请使用redrection

To redirect the output to the text file,use redrection

dotnet run 2> log.txt

注意:当dotnet主机写入STDERR流而不是STDOUT时,您需要'2>'重定向.您的常规日志记录将为STDOUT.希望这会有所帮助

note: You need the '2>' redirection as dotnet host writes to the STDERR stream and not STDOUT.Your regular logging will be STDOUT .Hope this helps

这篇关于检查.NET Core中动态加载的库的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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