I have a problem where my solution contains a node_modules folder with some libraries with long paths.
This files are not needed in output directory, becuase they are only needed in another build step.
When I run build command from Visual Studio, the build fails with errors MSB3027 nad MSB3021 both saying that files could not be copied to output directory. Error source file Microsoft.Common.CurrentVersion.targets.
I excluded the problematic folder from solution in a different ways:
<None Remove="App_Plugins\**\node_modules\**" />
<ItemGroup>
<Content Remove="App_Plugins\**\node_modules\**" />
<Compile Remove="App_Plugins\**\node_modules\**" />
<EmbeddedResource Remove="App_Plugins\**\node_modules\**" />
<None Remove="App_Plugins\**\node_modules\**" />
</ItemGroup>
but the Visual Studio tries to copy them anyway.
Error:
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5270,5): error MSB3027: Could not copy "C:\src\ORB\MyComp\src\Cms\Company.Cms\App_Plugins\welcome-dashboard\node_modules\@umbraco-cms\backoffice\dist-cms\packages\core\workspace\components\workspace-breadcrumb\workspace-variant-menu-breadcrumb\workspace-variant-menu-breadcrumb.kind.d.ts" to "bin\Debug\net8.0\App_Plugins\welcome-dashboard\node_modules\@umbraco-cms\backoffice\dist-cms\packages\core\workspace\components\workspace-breadcrumb\workspace-variant-menu-breadcrumb\workspace-variant-menu-breadcrumb.kind.d.ts". Exceeded retry count of 10. Failed.
Why does the dotnet build command work? Isn't MSBuild used in the end in both cases?
How to convince Visual Studio to leave those files?