最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - C# plugin fails on transitive dependencies when passing logger of main app to the plugin. How to avoid? - Stack Overflow

programmeradmin2浏览0评论

I have a .NET 9.0.2 application that should be using plugins as described in the documentation on .

This works with a shared project between the app and the plugins for the plugin interfaces. Via the IPlugin interface I want to pass an ILogger or an ILoggerFactory to the plugin so that the plugin can write logging that will appear in my main application's logfile. Because of this, the shared project references Microsoft.Extensions.Logging.

My first plugin is very simple and configured according to the manual and works fine and can log lines in my app's logfile. The reason is the false en runtime on the shared project reference in the plugin project, it only builds the plugin assembly to the output directory and doesn't add the plugin interfaces assembly, or it dependencies, and uses those of the app.

My second plugin is more complex and uses a number of nuget packages that it requires. One of those nuget packages also uses Microsoft.Extensions.Logging. I do not have control over how the nuget is build, I just add it. When I build the second plugin now, my output folder does not contain the shared interfaces and any of the assemblies it references, which is good. HOWEVER, it does contain the assembly from the nuget package, including all the references, and thus also the Microsoft.Extensions.Logging assembly that it references. When loading and using this second plugin the application fails because the ILoggerFactory from the plugin is no longer the same as the ILoggerFactory of the app (even though they are both 9.0.2). Using ExcludeAssets on the package reference is of course not an option, because then the whole nuget package is excluded from the output folder and then I get a missing dependency, and since it is a plugin, I also cannot add all the nuget packages of all the plugins I will be loading to my app (because then there is no point in making/using plugins).

How can I solve this so that it uses the Microsoft.Extensions.Logging from the app in that scenario, but I'm still able ot use the nuget package in my plugin?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论