问题
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:
main asp.net core project which dynamically loads plugins like mailservice.dll using reflection.
mailservice.dll library which exposes CheckMail() method (I use MimeKit as a IMAP helper).
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?
回答1:
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
After that just run using dotnet run and you will get full details
To redirect the output to the text file,use redrection
dotnet run 2> log.txt
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
来源:https://stackoverflow.com/questions/43792974/inspect-dependencies-for-dynamically-loaded-library-in-net-core