NopCommerce:如何通过更新自定义插件的项目构建输出路径来生成DLL文件

问题描述

我想为 nopcommerce 制作一个测试插件,正如 documentation 所说,我必须在 /plugins 目录中创建一个文件夹,名称应如下所示:

nop.Plugin.Widgets.Test

现在我需要更新项目构建输出路径。但我不知道我应该在哪里做!

因此,如果您知道我该怎么做并正确生成 DLL,请告诉我,我将不胜感激(我的职业依赖于此)

提前致谢。

解决方法

您应该更新刚刚创建的项目的 .csproj 文件中的输出路径。 我附上了一张图片作为在 Visual Studio 中点击的位置。该示例与您的情况相同,唯一不同的是所需插件的名称是“Payments.CheckMoneyOrder”而不是“Widgets.Test”。

接下来,编辑输出路径,如下面的 xml 所示。在您的情况下,这意味着将“Payments.CheckMoneyOrder”替换为“Wigets.Test”。 Link to image

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Copyright>Copyright © Nop Solutions,Ltd</Copyright>
    <Company>Nop Solutions,Ltd</Company>
    <Authors>Nop Solutions,Ltd</Authors>
    <PackageLicenseUrl></PackageLicenseUrl>
    <PackageProjectUrl>https://www.nopcommerce.com/</PackageProjectUrl>
    <RepositoryUrl>https://github.com/nopSolutions/nopCommerce</RepositoryUrl>
    <RepositoryType>Git</RepositoryType>
  <!--Edit your output path here! -->  
<OutputPath>..\..\Presentation\Nop.Web\Plugins\Payments.CheckMoneyOrder</OutputPath>
    <OutDir>$(OutputPath)</OutDir>
    <CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="logo.jpg" />
    <None Remove="plugin.json" />
    <None Remove="Views\Configure.cshtml" />
    <None Remove="Views\PaymentInfo.cshtml" />
    <None Remove="Views\_ViewImports.cshtml" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="logo.jpg">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="plugin.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="Views\Configure.cshtml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="Views\PaymentInfo.cshtml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="Views\_ViewImports.cshtml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\Presentation\Nop.Web.Framework\Nop.Web.Framework.csproj" />
    <ClearPluginAssemblies Include="$(MSBuildProjectDirectory)\..\..\Build\ClearPluginAssemblies.proj" />
  </ItemGroup>

  <!-- This target execute after "Build" target -->
  <Target Name="NopTarget" AfterTargets="Build">
    <!-- Delete unnecessary libraries from plugins path -->
    <MSBuild Projects="@(ClearPluginAssemblies)" Properties="PluginPath=$(MSBuildProjectDirectory)\$(OutDir)" Targets="NopClear" />
  </Target>

</Project>
```