By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe the bug

我使用命令 dotnet publish "myprojectname" -c release -o "out/to/path" -f netcoreapp2.1 发布我的Asp.net core 2.1 的网站,但是耗时非常的长,几乎都在10分钟以上,有时候甚至达到40分钟以上。

我的项目是一个前后端混合的结构,大概如下:

|-- web
      |-- node_modules
      |-- Controllers
      |-- src #这个目录用于存放前端代码
      |-- wwwroot 前端打包后的输出目录 

后端代码的编译过程很快2分钟以内结束,但是到了输出目录阶段就变得很慢。

我已经预先排查过原因,最后发现是,dotnet会扫描 node_modules目录,主要的消耗时间都是因为它。但是我试过了多种禁用手段都无法禁止dotnet扫描node_modules。

我的项目配置如下:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
	  <DefaultItemExcludes>$(DefaultItemExcludes);node_modules**</DefaultItemExcludes>
  </PropertyGroup>
  <ItemGroup>
    <Compile Remove="node_modules\**" />
    <Content Remove="node_modules\**" />
    <EmbeddedResource Remove="node_modules\**" />
    <None Remove="node_modules\**" />
  </ItemGroup>
	<ItemGroup>
		<Content Update="node_modules\**\*.*" CopyToPublishDirectory="Never" />
	</ItemGroup>
  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>
  <ItemGroup>
    <!--其他依赖-->
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
  </ItemGroup>
</Project>

Further technical details

  • Include the output of dotnet --info
  • > dotnet --info
    .NET SDK (reflecting any global.json):
     Version:   6.0.102
     Commit:    02d5242ed7
    Runtime Environment:
     OS Name:     Windows
     OS Version:  10.0.17763
     OS Platform: Windows
     RID:         win10-x64
     Base Path:   C:\Program Files\dotnet\sdk\6.0.102\
    Host (useful for support):
      Version: 6.0.2
      Commit:  839cdfb0ec
    .NET SDKs installed:
      2.1.818 [C:\Program Files\dotnet\sdk]
      6.0.102 [C:\Program Files\dotnet\sdk]
    .NET runtimes installed:
      Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
      Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
      Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.NETCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      Microsoft.WindowsDesktop.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
    To install additional .NET runtimes or SDKs:
      https://aka.ms/dotnet-download
    Partial translation:

    Describe the bug

    I'm using commandline dotnet publish "myprojectname" -c release -o "out/to/path" -f netcoreapp2.1 publishing my Asp.net core 2.1 website,but it took very long,almost cases needs more than 10 minuites,sometimes even need more than 40 minuites。

    Here is my project structure:

    |-- web
          |-- node_modules
          |-- Controllers
          |-- src  // This folder contains frontend code
          |-- wwwroot // This folder contains built frontend
    

    Backend can be built in 2min, 但是到了输出目录阶段就变得很慢。

    我已经预先排查过原因,最后发现是,dotnet scans folder node_modules, this is the main issue that wastes time。但是我试过了多种禁用手段都 can't stop dotnet from scanning node_modules

    Here is my project configuration:

    <PropertyGroup>
        <TargetFramework>netcoreapp2.1</TargetFramework>
    	  <DefaultItemExcludes>$(DefaultItemExcludes);node_modules**</DefaultItemExcludes>
      </PropertyGroup>
      <ItemGroup>
        <Compile Remove="node_modules\**" />
        <Content Remove="node_modules\**" />
        <EmbeddedResource Remove="node_modules\**" />
        <None Remove="node_modules\**" />
      </ItemGroup>
    	<ItemGroup>
    		<Content Update="node_modules\**\*.*" CopyToPublishDirectory="Never" />
    	</ItemGroup>
      <ItemGroup>
        <Folder Include="wwwroot\" />
      </ItemGroup>
      <ItemGroup>
        <!-- Other dependencies -->
        <PackageReference Include="Microsoft.AspNetCore.App" />
        <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
      </ItemGroup>
    </Project>
    

    Further technical details

  • Include the output of dotnet --info
  • dotnet --info
    .NET SDK (reflecting any global.json):
    Version: 6.0.102
    Commit: 02d5242

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

    Host (useful for support):
    Version: 6.0.2
    Commit: 839cdfb0ec

    .NET SDKs installed:
    2.1.818 [C:\Program Files\dotnet\sdk]
    6.0.102 [C:\Program Files\dotnet\sdk]

    .NET runtimes installed:
    Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
    Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
    Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.WindowsDesktop.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

    To install additional .NET runtimes or SDKs:
    https://aka.ms/dotnet-download

    Thanks for creating this issue! We believe this issue is related to NuGet tooling, which is maintained by the NuGet team. Thus, we closed this one and encourage you to raise this issue in the NuGet repository instead. Don’t forget to check out NuGet’s contributing guide before submitting an issue!

    If you believe this issue was closed out of error, please comment to let us know.

    Happy Coding!

    @chiikin 我这个项目没有用jenkins做自动化,用bat文件里面加了publish命令,每次手动点击做发布。
    上午publish的时候加了 -v diag 参数排查了一下,主要下面两个target命令执行时间过长影响了发布时间

    5479 毫秒 _FilterRestoreGraphProjectInputItems           1 次调用
    74464 毫秒 _IncludePrePublishGeneratedContent         1 次调用
    

    查了些资料,应该是发布时文件过多造成检查时间过长,目前通过禁用EnableDefaultContentItems的方式解决了。
    需要复制到发布文件夹的内容通过Content Include加进去

    PropertyGroup ->
    <EnableDefaultContentItems>false</EnableDefaultContentItems>
    <DefaultItemExcludes>$(DefaultItemExcludes);wwwroot/**/node_modules/**</DefaultItemExcludes>
    ItemGroup ->
    <Content Include="wwwroot/**" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
    

    如果通过jenkins命令来做全量复制的话,可以把上面的CopyToPublishDirectory设置为Never,这样省去检查的时间,会更快一些。

    参考issue:#12488