Skip to content

Handle project instances that only differ in global properties - #56021

Merged
tmat merged 4 commits into
dotnet:release/11.0.1xxfrom
tmat:DuplicateProjectIds11
Sep 10, 2026
Merged

tmat merged 4 commits into
dotnet:release/11.0.1xxfrom
tmat:DuplicateProjectIds11

Conversation

@tmat

@tmat tmat commented Aug 29, 2026 •

Copy link
Copy Markdown
Member

Fixes #54552

Copilot AI lite review requested due to automatic review settings August 29, 2026 18:36
@tmat
tmat requested a review from a team as a code owner August 29, 2026 18:36
@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.

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR addresses dotnet watch crashing when a project graph contains multiple ProjectInstances that share the same (ProjectPath, TargetFramework) but differ in other global properties (regression noted in #54552). The change deduplicates project instances for dotnet-watch’s internal maps and adds a regression test asset + unit test.

Changes:

  • Deduplicate inner-build ProjectGraphNodes by (ProjectPath, TargetFramework) and warn when duplicates differ only in other global properties.
  • Avoid ToDictionary over the full project graph nodes when capturing restored project instances by using a deduped map instead.
  • Add a new test asset and a unit test that exercises duplicate project instances caused by ProjectReference AdditionalProperties.
File summaries
File Description
test/TestAssets/TestProjects/ProjectsWithGlobalProperties/Library/LibraryClass.cs New test library source that changes behavior based on a global-property-driven constant.
test/TestAssets/TestProjects/ProjectsWithGlobalProperties/Library/Library.csproj New test library project that varies outputs per global property and isolates output paths.
test/TestAssets/TestProjects/ProjectsWithGlobalProperties/App/Program.cs New test app that loads different library outputs to validate the scenario.
test/TestAssets/TestProjects/ProjectsWithGlobalProperties/App/App.csproj New test app referencing the same project twice with different AdditionalProperties.
test/dotnet-watch.Tests/Build/ProjectGraphFactoryTests.cs Adds regression coverage for duplicate project instances with different global properties.
src/Dotnet.Watch/Watch/Build/LoadedProjectGraph.cs Introduces a deduped inner-build node map and warning for global-property-only differences.
src/Dotnet.Watch/Watch/Build/EvaluationResult.cs Switches restored-project snapshot creation to use the deduped instance map.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🔍 Build Failure Analysis

Summary — A C# syntax error in a newly-added test method breaks compilation of dotnet-watch.Tests across every build leg.

Root cause: invalid escaped quotes inside an interpolated-string expression hole

The new ProjectsWithGlobalProperties test contains this line:

var actual = map.Select(entry => $"{entry.Key.ProjectPath} TFM={entry.Key.TargetFramework} X={(entry.Value.GlobalProperties.TryGetValue(\"X\", out var x) ? x : \"\")}").ToArray();

Inside the {...} interpolation hole, the code is ordinary C# and needs normal string literals ("X", ""). Instead it uses backslash-escaped quotes (\"X\", \"\"), which are only valid for escaping quotes inside the outer string's literal text — not for nested string literals within an interpolation hole. The Roslyn parser sees the stray \ characters as unexpected tokens, which cascades into the reported CS1003/CS1073/CS1056/CS1026/CS1002/CS1513 errors at lines 137 and 142 and ultimately fails CoreCompile for dotnet-watch.Tests on every OS/leg (Windows, Linux, macOS, x64/arm64, AOT and full-framework).

Affected files / errors

Proposed fix

-        var actual = map.Select(entry => $"{entry.Key.ProjectPath} TFM={entry.Key.TargetFramework} X={(entry.Value.GlobalProperties.TryGetValue(\"X\", out var x) ? x : \"\")}").ToArray();
+        var actual = map.Select(entry => $"{entry.Key.ProjectPath} TFM={entry.Key.TargetFramework} X={(entry.Value.GlobalProperties.TryGetValue("X", out var x) ? x : "")}").ToArray();

Build overview

Every one of the 10 build legs (Windows x64, Windows x64 AOT, Windows x64 FullFramework, Windows arm64 AOT, Linux x64, Linux x64 AOT, Linux arm64, Linux arm64 AOT, Mac arm64, Mac arm64 AOT) reports the identical set of CoreCompile/Csc errors for test/dotnet-watch.Tests/dotnet-watch.Tests.csproj, confirming this is a genuine C# compile failure and not an environment-specific flake.

All MSBuild errors
Code Project File:Line Message
CS1003 dotnet-watch.Tests ProjectGraphFactoryTests.cs:142 Syntax error, ')' expected
CS1073 dotnet-watch.Tests ProjectGraphFactoryTests.cs:137 Unexpected token ';'
CS1056 dotnet-watch.Tests ProjectGraphFactoryTests.cs:137 Unexpected character ''
CS1026 dotnet-watch.Tests ProjectGraphFactoryTests.cs:137 ) expected
CS1026 dotnet-watch.Tests ProjectGraphFactoryTests.cs:144 ) expected
CS1002 dotnet-watch.Tests ProjectGraphFactoryTests.cs:144 ; expected
CS1513 dotnet-watch.Tests ProjectGraphFactoryTests.cs:144 } expected

🤖 Generated by the Build Failure Analysis workflow using (a href="(dev.azure.com/redacted) · commit 280811e

🤖 Automated content by GitHub Copilot. Generated by the Build Failure Analysis workflow. · auto · 127.6 AIC · ⌖ 1.91 AIC · ⊞ 7.1K · [◷]( · ◷)

@github-actions github-actions Bot 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.

🤖 Automated content by GitHub Copilot. Generated by the Build Failure Analysis workflow. · auto · 127.6 AIC · ⌖ 1.91 AIC · ⊞ 7.1K · ◷

@tmat
tmat merged commit 0af300c into dotnet:release/11.0.1xx Sep 10, 2026
22 checks passed
@tmat
tmat deleted the DuplicateProjectIds11 branch September 10, 2026 00:13
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc2 milestone Sep 10, 2026

This branch had an error being deployed

1 failed deployment
copilot-pat-pool — f622abd1 Deployed Sep 10, 2026 by tmat via pre_activation #3951
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Watch dotnet-watch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants