dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.74k stars 1.07k forks source link

node_modules folder is not published #8971

Closed HaythemJ closed 4 years ago

HaythemJ commented 6 years ago

Steps to reproduce

dotnet core 2.0 Visual Studio 2017 15.5.1 Publish Web Application

Expected behavior

folder with name node_modules should be published like any other folder

Actual behavior

folder with name node_modules is not published

Environment data

dotnet --info output: .NET Command Line Tools (2.1.3)

Product Information: Version: 2.1.3 Commit SHA-1 hash: a0ca411ca5

Runtime Environment: OS Name: Windows OS Version: 10.0.16299 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.3\

Microsoft .NET Core Shared Framework Host

Version : 2.0.4 Build : 7f262f453d8c8479b9af91d34c013b3aa05bc1ff

I have a Web Application where I put Javascript files under wwwroot/lib/vendors/ like below:

image

When publishing the folder wwwroot/lib/vendors/node_modules is not published in the output folder which leads to missing libraries.

Is there a way to force the publish of that folder?

dasMulli commented 6 years ago

You may find one of the solutions in https://github.com/dotnet/cli/issues/4062 helpful.

Easiest way is to add this to your csproj file

<ItemGroup>
  <Content Include="wwwroot\lib\vendors\node_modules\**" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
HaythemJ commented 6 years ago

It works, thank you. But I have to remove other entries like below, othewise the publish won't work saying that there is duplicate entries. I am wondering why the Content Include did not work without the attribute CopyToPublishDirectory

`<ItemGroup>
         <Content Include="wwwroot\lib\vendors\node_modules\**"   
             CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
`
dasMulli commented 6 years ago

It depends on what you already have in your csproj file.. if you clicked "include in project" once, you'll likely have a huge load of those include items.. Best to remove them all and just have the wildcard include. the other option would be <Content Update=... CopyTo.. /> but that would be a hard-to-manage csproj file.

livarcocc commented 6 years ago

@dasMulli thanks for replying on this issue. @HaythemJ let us know if the suggestions above do not work for you.

HaythemJ commented 6 years ago

It works great. Thank you for the support. I will close the issue.