sdk: dotnet publish takes too long, about 5 minutes

I am using following command dotnet publish -p:PublishProfile=Properties\PublishProfiles\FolderProfile.pubxml -v:d then it hangs since 1:7>Done building target "_RazorGetCopyToPublishDirectoryItems" in project "project.csproj".

Other projects publish so quick. I removed all not necessary folders from project.

Time Elapsed 00:04:48.26

Further technical details

  • ASP.NET Core version 3.1.3
  • IDE VS 16.5

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

I can confirm I’m having this issue as well, however, way more severe, an hour+ and MSBuild using 10-20GB/32GB of RAM to do a reactjs publish (net 7 web api project). Applied these csproj changes and it went from an hour+ down to 30sec

Your project has a fair number of “Content” files and it appears this one target that’s inspecting them might be taking way too long.

Could you try an experiment to see if it helps? To your project file add:

<PropertyGroup>
  <EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>

 <ItemGroup>
    <!-- Publish everything under wwwroot, all JSON files, all config files and all Razor files -->
    <Content Include="wwwroot\**" ExcludeFromSingleFile="true" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
    <Content Include="**\*.config" ExcludeFromSingleFile="true" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(DefaultWebContentItemExcludes)" />
    <Content Include="**\*.json" ExcludeFromSingleFile="true" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(DefaultWebContentItemExcludes)" />

    <!-- Set CopyToPublishDirectory to Never for items under AppDesignerFolder ("Properties", by default) to avoid publishing launchSettings.json -->
    <Content Update="$(AppDesignerFolder)\**" CopyToPublishDirectory="Never" Condition="'$(AppDesignerFolder)' != ''"/>   

    <!-- Remove Content items from other item types (in a way that CPS understands) -->
    <None Remove="wwwroot\**;**\*.json;**\*.config" />
    <Compile Remove="wwwroot\**" />
    <EmbeddedResource Remove="wwwroot\**" />
</ItemGroup>