构建没有运行时文件夹但在 nopcommerce 4.40.net 5 和 VS 2019中包含 nuget 包的项目

问题描述

我正在为 nopcommerce 开发插件

我使用的是 VS 2019 和 nopcommerce 4.40.4(.net 5)

我应该在我的插件中使用 nuget 包,

如果我将 copyLocalLockFileAssemblies 设置为 true,当我构建我的项目时,它会创建运行时文件夹,大约 65 MB,

如果我将 copyLocalLockFileAssemblies 设置为 false,它不会创建运行时文件夹,但是,我应该使用的 nuget 包的 dll 不包含在构建文件夹中,

你能帮我解决这个问题吗?

注意:将copy local设置为no,当我更改项目中使用的nop.Services时没有任何区别>

这是我的 csproj,我的包是 > SmsIrRestful.NetCore :

    <Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <OutputPath>..\..\Presentation\nop.Web\Plugins\AttributeStockSMS</OutputPath>
    <OutDir>$(OutputPath)</OutDir>
    <!--Set this parameter to true to get the dlls copied from the NuGet cache to the output of your project.
    You need to set this parameter to true if your plugin has a nuget package 
    to ensure that the dlls copied from the NuGet cache to the output of your project-->
    <copyLocalLockFileAssemblies>false</copyLocalLockFileAssemblies>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <ItemGroup>
    <ClearPluginAssemblies Include="$(MSBuildProjectDirectory)\..\..\Build\ClearPluginAssemblies.proj" />
  </ItemGroup>

  <ItemGroup>
    <None Remove="plugin.json" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="plugin.json">
      <copyToOutputDirectory>PreserveNewest</copyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <packagereference Include="SmsIrRestful.NetCore" Version="1.1.5" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\Libraries\nop.Services\nop.Services.csproj">
      <Private>false</Private>
    </ProjectReference>
  </ItemGroup>
  <Target Name="nopTarget" AfterTargets="Build">
    <!-- Delete unnecessary libraries from plugins path -->
    <MSBuild Projects="@(ClearPluginAssemblies)" Properties="PluginPath=$(MSBuildProjectDirectory)\$(OutDir)" Targets="nopClear" />
  </Target>
</Project>

解决方法

不要使用 NuGet 引用,而是包含该 NuGet 包的 dll 文件。例如,您将使用 TaxJar 库,然后按照以下步骤操作。

  1. 添加了 NuGet 参考。 enter image description here
  2. 右键单击 NuGet 包并转到属性。 enter image description here
  3. 从属性值复制路径值,如下所示。 enter image description here
  4. 在文件资源管理器中转到该路径。 enter image description here
  5. 从那里找到 dll 文件,复制粘贴到您的插件文件夹中并添加引用。 enter image description here
  6. 也对依赖包(如果有)重复相同的过程。 enter image description here
  7. 从属性标记为复制本地enter image description here