Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
node_modules not copied to output folder when running dotnet publish #4062
Steps to reproduce
I've created a GitHub repo with a project showing this.
node_modules should be copied to the output directory when running dotnet publish because:
It should be possible to include the node_modules directory or any other file or directory in the publish output, even if these files or directories does not exist before running scripts using the prepublish hook.
When running dotnet publish on a webapp with dependencies on node packages, the node_modules directory is not copied to the output directory even if npm install is run with the prepublish hook and node_modules is specified to be included.
It works if the node_modules directory exists before running dotnet publish, but when you run dotnet publish for the first time, node_modules will not exist before
Try running dotnet publish a second time, and you will see that node_modules is copied.
.NET Command Line Tools (1.0.0-preview2-003121)
You could also remove the default node_modules exclude that the web-sdk adds by adding this to the csproj file:
<PropertyGroup> <DefaultItemExcludes>$([System.String]::Copy($(DefaultItemExcludes)).Replace(';**\node_modules\**',''))</DefaultItemExcludes> <DefaultItemExcludes>$([System.String]::Copy($(DefaultItemExcludes)).Replace(';node_modules\**',''))</DefaultItemExcludes> </PropertyGroup>
However this will make building and publishing a bit slower since msbuild will scan the entire node_modules folder which may be slow.
@zelliott haven't looked at it in detail but I guess these packages will pull in a lot of dependencies and tracing them all down would be hard..
Any folder or file that is not yet part of the project can still be imported manually (using
<ItemGroup> <Content Include="node_modules\foo\**" CopyToPublishDirectory="PreserveNewest" /> </ItemGroup>