I am using Nopcommerce 4.2 and trying to create a custom Plugin.
At runtime I get the error:
System.Exception: 'A plugin with 'DiscountRequirement.MustBeAssignedToCustomerRole' system name is already defined
When I go to Nop.Web/Plugins, I can see all the plugins that have been built - including mine. When I look in my custom plugin, I can see a folder folder called Plugins, this contains all the other plugins that have been built.
I have looked at my csproj and compared it against nop default plugins and cannot work out why mine builds all the plugins again.
to be clear the structure that is being created is:
Nop.Web
Plugins/
--DiscountRules.CustomerRoles
--ExchangeRate.EcbExchange
--...Other plugins...
--My.Plugin/
----App_Data
----Areas
----Plugins/
-----DiscountRules.CustomerRoles
-----ExchangeRate.EcbExchange
-----...Other plugins...
my project file
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<OutputPath>..\..\Presentation\Nop.Web\Plugins\Widgets.MostViewedProducts</OutputPath>
<OutDir>$(OutputPath)</OutDir>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Domain\**" />
<Content Remove="Domain\**" />
<EmbeddedResource Remove="Domain\**" />
<None Remove="Domain\**" />
</ItemGroup>
<ItemGroup>
<None Remove="logo.jpg" />
<None Remove="plugin.json" />
</ItemGroup>
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<Content Include="logo.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Update="Areas\Admin\Views\BuilderProductAttribute\Create.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProductAttribute\Edit.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProductAttribute\List.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Areas\Admin\Views\BuilderProductAttribute\_CreateOrUpdate.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\Create.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\Edit.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\List.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\ProductAttributeCatalogCreatePopup.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\ProductAttributeMappingCreate.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\ProductAttributeMappingEdit.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdate.Attributes.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdate.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdate.Info.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdate.SEO.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdateProductAttributeMapping.Catalog.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdateProductAttributeMapping.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdateProductAttributeMapping.Info.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\ProductBuilder\Configure.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\_ViewImports.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\BuilderProduct\AttributeMappingProduct.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\BuilderProduct\Details.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\BuilderProduct\ProductDetails.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\BuilderProduct\_CatalogSelectors.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\BuilderProduct\_ProductBox.ProductBuilder.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\_ViewImports.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Areas\Admin\Controllers\" />
<Folder Include="Areas\Admin\Extensions\" />
<Folder Include="Areas\Admin\Factories\" />
<Folder Include="Areas\Admin\Infrastructure\" />
<Folder Include="Areas\Admin\Models\" />
<Folder Include="Areas\Admin\Views\" />
<Folder Include="Controllers\" />
<Folder Include="Extensions\" />
<Folder Include="Factories\" />
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Presentation\Nop.Web.Framework\Nop.Web.Framework.csproj" />
<ProjectReference Include="..\..\Presentation\Nop.Web\Nop.Web.csproj" />
<ClearPluginAssemblies Include="$(MSBuildProjectDirectory)\..\..\Build\ClearPluginAssemblies.proj" />
</ItemGroup>
<ItemGroup>
<None Update="Views\Shared\Components\Default.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Views\_ViewImports.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</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>
EDIT
Plugin.json
{
"InstalledPluginNames": [
"Widgets.GoogleAnalytics",
"Widgets.NivoSlider",
"ExternalAuth.Facebook",
"Misc.Cards",
"Payments.PayPalSmartPaymentButtons",
"Payments.PayPalStandard",
"Catalog.SkipToProduct"
],
"PluginNamesToUninstall": [],
"PluginNamesToDelete": [
"DiscountRequirement.MustBeAssignedToCustomerRole",
"CurrencyExchange.ECB",
"Misc.SendinBlue",
"Payments.CheckMoneyOrder",
"Payments.Manual",
"Payments.Qualpay",
"Payments.Square",
"Pickup.PickupInStore",
"Shipping.FixedByWeightByTotal",
"Shipping.UPS",
"Tax.Avalara",
"Tax.FixedOrByCountryStateZip"
],
"PluginNamesToInstall": []
}
the problem might be a reference, because when you add the reference DiscountRequirement.MustBeAssignedToCustomerRole to another plugin you need to put in the property Copylocal = false.