.Net插件体系结构不能与Nuget一起使用 [英] .Net Plugin Architecture Not Working with Nuget

查看:40
本文介绍了.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:

MyConsoleApp \ bin \ x86 \ Debug \ netcoreapp3.1 \ runtimes \ win-x86 \ native \ e_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.Sqlite lib插件项目没有运行时文件夹,并且当 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插件项目,因此只需执行

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 文件中写入此目标:

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

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

        <ItemGroup>
            <CopyItems Include="..\MsTest\bin\Debug\xxx\runtimes\**\*.*" />
        </ItemGroup>

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

2)除外,您还可以安装名为 sqlite ,此程序包仅包含 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天全站免登陆