OK, I've managed to figure out where I went wrong. My plugin was fine, but I had one of its dependencies set up incorrectly.
The dependency (Blogifier.Core) has dependencies on Nop.Web and Nop.Web.Framework and these did not have Copy Local set to false. Building this project created the extra folders.
Since my plugin does create a local copy of Blogifier.Core, it pulled in all these extra folders as part of that process.
In the end that was an easy fix.
If you're still having this problem for any other reason that you haven't figured out yet, there is a simple workaround that will save you from having to manually delete the extra folders and files. Change your Plugin.csproj file to delete them after building, like this:
<!-- 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" />
<!-- Delete extra folders and files from plugin output directory -->
<RemoveDir Directories="$(OutDir)\App_Data;$(OutDir)\Areas;$(OutDir)\Plugins;$(OutDir)\Themes" />
<Delete Files="$(OutDir)\appSsettings.json;$(OutDir)\appsettings.Development.json;$(OutDir)\web.config"/>
</Target>
All the best,
Simon
portraitsbysimonbland.com