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

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

问题描述

我正在尝试创建使用来自外部 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

注意:您需要2>"重定向,因为 dotnet 主机写入 STDERR 流而不是 STDOUT.您的常规日志记录将是 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 核心中动态加载的库的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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