Skip to content

[release/10.0.4xx] Check each referenced project once in dotnet format - #57019

Merged
jasonmalinowski merged 2 commits into
dotnet:release/10.0.4xxfrom
jasonmalinowski:backport-dotnet-format-recursion-fix-to-10.0.4xx
Nov 18, 2026
Merged

jasonmalinowski merged 2 commits into
dotnet:release/10.0.4xxfrom
jasonmalinowski:backport-dotnet-format-recursion-fix-to-10.0.4xx

Conversation

@jasonmalinowski

Copy link
Copy Markdown
Member

Backport of #56621 to release/10.0.4xx. Fixes #56363 for .NET 10.

#56621 merged to main on 2026-10-28.

Description

Before running analyzers, dotnet format style / dotnet format analyzers checks that every referenced project loaded by recursively walking ProjectReferences. The walk never remembers which projects it already checked, so a shared dependency is re-walked once per path that reaches it, which is exponential in the depth of the reference graph.

This replaces the recursion with a single pass over the project and its transitive dependencies from the solution's cached ProjectDependencyGraph, so each project is checked once.

This is a manual port, not a cherry-pick. On this branch the check is the synchronous AllReferencedProjectsLoaded (an mscorlib.dll metadata-reference check) under src/BuiltInTools/dotnet-format, rather than the async compilation check on main. The port keeps this branch's check exactly as is and changes only how the graph is walked. The test is translated from MSTest to xUnit.

Customer Impact

On solutions with dense project-reference graphs (for example, ones using DisableTransitiveProjectReferences), dotnet format style / analyzers runs for minutes to hours. #56363 reports 11.5 minutes on a 30-project repro and 14+ hours on a 380-project solution. Teams that use dotnet format --verify-no-changes as a CI gate can't run it. The only workarounds are formatting project by project or skipping the analyzer passes.

Regression?

No. The unmemoized walk is long-standing; it is also present in .NET 8 (dotnet/format).

Risk

Low. The change is limited to the pre-analysis reference check. The set of projects checked is the same (the project plus its transitive project references), and so is the per-project check. Any dependency that fails the check still skips the project with the existing "required references did not load" warning.

Testing

New AnalyzerRunnerTests: a dense 40-project graph (each project references every earlier one) completes in seconds; without the fix it effectively never finishes and the test harness's hang detection trips.

@jasonmalinowski
jasonmalinowski requested a review from a team as a code owner November 10, 2026 01:40
Copilot AI balanced review requested due to automatic review settings November 10, 2026 01:40
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the reference-walk performance backport.

No open issues 🎉

What changed in this PR

Backports the dotnet format reference-walk performance fix to release/10.0.4xx, addressing excessive processing time on dense project-reference graphs while preserving the branch’s existing reference-validation behavior.

Changes:

  • Replaces recursive traversal with a cached dependency-graph lookup so each reachable project is checked once per validation.
  • Adds an xUnit regression test using 40 densely connected projects, verifying the expected diagnostic and no logged warnings.
File Description
test/​dotnet-format.UnitTests/​Analyzers/​AnalyzerRunnerTests.cs Adds dense-graph regression coverage for analyzer execution.
src/​Dotnet.Format/​dotnet-format/​Analyzers/​AnalyzerRunner.cs Uses transitive dependency enumeration while retaining the mscorlib.dll validation check.

Review effort: Balanced

@jasonmalinowski jasonmalinowski changed the title Backport dotnet format recursion fix to 10.0.4xx [release/10.400] Check each referenced project once in dotnet format Nov 10, 2026
@jasonmalinowski
jasonmalinowski force-pushed the backport-dotnet-format-recursion-fix-to-10.0.4xx branch from 361e9f4 to 4f75220 Compare November 14, 2026 01:21
@jasonmalinowski jasonmalinowski changed the title [release/10.400] Check each referenced project once in dotnet format [release/10.0.4xx] Check each referenced project once in dotnet format Nov 16, 2026
@jasonmalinowski

Copy link
Copy Markdown
Member Author

This is blocked on #56869 merging.

Backport of dotnet#56621 to release/10.0.1xx.

Before running analyzers, AnalyzerRunner recursively walks every project
reference to confirm the runtime references loaded. Shared dependencies
are re-walked on every path that reaches them, so the cost grows
exponentially with the depth of the reference graph. Dense graphs (e.g.
solutions using DisableTransitiveProjectReferences) make `dotnet format
style` and `dotnet format analyzers` take minutes to hours.

Replace the recursion with a single pass over the project and its
transitive dependencies from the solution's cached
ProjectDependencyGraph, so each project is checked exactly once.

This is a manual port: this branch keeps its existing synchronous
mscorlib.dll check rather than main's compilation-based check, and the
tests are translated from MSTest to xUnit.

Fixes dotnet#56363
Drop the custom timeout wrapper; the test harness already dumps hung
tests, so a regression to the exponential walk trips that instead.

Drop the missing-corlib tests: the old recursive walk already reported
broken dependencies correctly, so they do not guard the regression this
change fixes. With one caller left, inline the graph construction.
@jasonmalinowski
jasonmalinowski force-pushed the backport-dotnet-format-recursion-fix-to-10.0.4xx branch from 4f75220 to 8ea6ef3 Compare November 18, 2026 18:50
@jasonmalinowski
jasonmalinowski merged commit 96718bb into dotnet:release/10.0.4xx Nov 18, 2026
27 checks passed
@jasonmalinowski
jasonmalinowski deleted the backport-dotnet-format-recursion-fix-to-10.0.4xx branch November 18, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants