.Net 插件架构不适用于 Nuget [英] .Net Plugin Architecture Not Working with Nuget

查看:36
本文介绍了.Net 插件架构不适用于 Nuget的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个加载插件的 .Net Core 3.1 控制台应用程序.我的插件之一连接到 Sqlite,因此它对 Microsoft.Data.Sqlite 有 Nuget 依赖.但是,由于以下路径不存在,我在加载/运行插件时从控制台应用程序中收到一个缺少的 DLL 异常:

I have a .Net Core 3.1 console application that loads plugins. One of my plugins connects to Sqlite and so it has a Nuget dependency on Microsoft.Data.Sqlite. However, I'm getting a missing DLL exception from the console app when loading/running the plugin because the following path doesn't exist:

MyConsoleAppinx86Debug etcoreapp3.1 untimeswin-x86 ativee_sqlite3.dll

MyConsoleAppinx86Debug etcoreapp3.1 untimeswin-x86 ativee_sqlite3.dll

我还有一个 MsTest 项目来测试这个 Sqlite 插件项目.它没有同样的问题.显然,如果 Visual Studio 项目 (1) 是某种可执行文件并且 (2) 具有相关的 Nuget 或项目引用,则 runtimes 文件夹和内容将自动存在.

I also have an MsTest project which tests this Sqlite plugin project. It does not have the same problem. Apparently the runtimes folder and contents will automatically exist if a Visual Studio project (1) is some kind of executable and (2) has a pertinent Nuget or project reference.

按照这些规则,我的三个 Visual Studio 项目中有两个没有运行时文件夹:

Following those rules, two of my three Visual Studio projects do not have the runtimes folder:

  • 该插件对 Microsoft.Data.Sqlite 有 Nuget 依赖,但没有 runtimes 文件夹,因为该插件项目是 DLL...不是可执行文件.
  • 测试 Sqlite 插件的 MsTest 项目确实具有 runtimes 文件夹和内容,因为 (1) 它是一种可执行文件和 (2) 它具有对插件项目的项目引用(后者又引用 Nuget 包).
  • 主控制台应用程序是一个可执行文件,但(有意)没有对插件的项目引用.因此它没有 runtimes 文件夹.
  • The plugin has a Nuget dependency on Microsoft.Data.Sqlite, but does not have the runtimes folder because the plugin project is a DLL...not an executable.
  • The MsTest project which tests the Sqlite plugin does have the runtimes folder and contents because (1) it it is a type of executable and (2) it has a project reference to the plugin project (which in turn references the Nuget package).
  • The main console app is an executable, but (intentionally) doesn't have a project reference to the plugin. Thus it does not have the runtimes folder.

我该如何解决这个问题?作为一个黑客,我只是将丢失的 DLL 复制到控制台应用程序的输出目标目录中.

How do I solve this? As a hack I have simply copied the missing DLL into the output target directory for the console app.

另外,如果我从控制台应用程序添加一个项目引用到插件,这个问题就解决了.但是,如前所述,我不希望控制台应用程序具有对任何插件的项目引用.插件应该是动态发现的.我认为修复此问题可能与创建 nuspec 文件有关.但是,nuspec 文件的文档 没有关于解决这个问题的评论.

Also, if I add a project reference from the console app to the plugin, this problem is solved. But, as stated, I don't want the console app to have project references to any plugins. Plugins should be discovered dynamically. I think fixing this may have something to do with creating a nuspec file. However, the documentation for nuspec files has no commentary about addressing this.

推荐答案

.Net 插件架构不适用于 Nuget

.Net Plugin Architecture Not Working with Nuget

正如您所说,引用 Microsoft.Data.Sqlitelib 插件 项目没有运行时文件夹,并且当exe 项目引用lib plugins 项目,runtimes 文件夹将复制到exe 项目的输出文件夹中.

Just as you said that, the lib plugins project which references Microsoft.Data.Sqlite does not have the runtime folder and when an exe project reference the lib plugins project, the runtimes folder will be copied into the the exe project's output folder.

解决方案

1) 由于您不想为控制台项目引用 lib 插件 项目,您可以只做一个 MsTest 项目的运行时复制 msbuild 中的任务文件夹.

1) Since you do not want to reference the lib plugins project for the console project, you can just do a copy task in msbuild from the MsTest project's runtimes folder.

Net Core 3.1控制台应用程序的xxx.csproj文件中写入这个target:

Write this target in the xxx.csproj file of Net Core 3.1 console application:

<Target Name="Copy_Runtimes" AfterTargets="Build">

        <ItemGroup>
            <CopyItems Include="..MsTestinDebugxxx
untimes***.*" />
        </ItemGroup>

        <Copy SourceFiles="@(CopyItems)" DestinationFolder="$(OutputPath)runtimes\%(RecursiveDir)%(Filename)%(Extension)')"></Copy>
</Target>

2) 此外,您还可以安装名为 sqlitenet core 3.1 控制台应用程序中,并且此包仅包含 runtimes 文件夹,不包含其他用于使用的 com dll.

2) Besides, you can also install the nuget package called sqlite in the net core 3.1 console application, and this package only contains the runtimes folder and does not include other com dlls for using.

它实际上是一个提供runtimes文件夹的纯服务包.

It is actually a pure service package for providing runtimes folder.

你可以直接在你的控制台项目中安装这个包,如果你对此不满意,你只能尝试解决方案1来解决问题.

You can install this package in your console project directly and if you are not satisfied with this, you can only try solution 1 to solve the issue.

这篇关于.Net 插件架构不适用于 Nuget的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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