sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Add EnableDefaultItems=false optimization for restore operations

Open Copilot opened this issue 8 months ago • 0 comments

Improves restore performance by disabling default item globbing during restore operations, addressing significant performance issues on projects with large numbers of files.

Problem

During dotnet restore operations, MSBuild spends excessive time on default item globbing (Compile, EmbeddedResource, None items) which can take 45+ seconds on projects with 100k+ files. Restore operations don't actually need these items to be evaluated, making this globbing unnecessary overhead.

Solution

Automatically adds EnableDefaultItems=false property to MSBuild arguments during restore operations while respecting user-provided values to avoid conflicts.

Changes

  • Constants.AddRestoreOptimizations(): New method that adds EnableDefaultItems=false if user hasn't already specified it
  • RestoreCommand.CreateForwarding(): Apply optimization for explicit restore commands (dotnet restore)
  • RestoringCommand.GetSeparateRestoreCommand(): Apply optimization for implicit restore scenarios (dotnet build without --no-restore)
  • Comprehensive property parsing: Handles multiple MSBuild property syntax formats (-property:, -p:, --property:) with case-insensitive matching

User Experience

  • Transparent: Users won't notice any behavior changes except faster restores
  • Respects user preferences: If user explicitly sets EnableDefaultItems=true/false, their value is preserved
  • Backward compatible: No breaking changes to existing workflows

Testing

Added comprehensive unit tests covering:

  • Basic optimization behavior
  • User override scenarios with various property syntax formats
  • Case-insensitive property matching
  • Integration with both explicit and implicit restore paths

Expected Impact

Based on the original performance analysis, this should reduce restore evaluation time from ~45 seconds to ~300ms on projects with large file counts.

Fixes #49415.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • josvsblobprodcus372.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/sdk/sdk/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/sdk/sdk/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/sdk/sdk/artifacts/toolset/10.0.0-beta.25315.102.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Jun 16 '25 20:06 Copilot