Skip to content

Avoid a conditionally skipped InitialTarget in Workarounds.targets - #17329

Merged
ViktorHofer merged 1 commit into
dotnet:mainfrom
ViktorHofer:fix-initialtarget-skipped-results-cache
Aug 13, 2026
Merged

ViktorHofer merged 1 commit into
dotnet:mainfrom
ViktorHofer:fix-initialtarget-skipped-results-cache

Conversation

@ViktorHofer

Copy link
Copy Markdown
Member

Problem

NormalizeNetCoreSdkRootCasing is declared as an InitialTarget on Workarounds.targets:

<Project InitialTargets="NormalizeNetCoreSdkRootCasing">

InitialTargets on an imported file aggregates into the importing project's InitialTargets, and Workarounds.targets is imported by every project that uses the Arcade SDK. The target's condition requires MSBuildRuntimeType == 'Full', so on every non-Windows build it is recorded as TargetResultCode.Skipped.

MSBuild's ResultsCache.SatisfyRequest refuses to satisfy a build request when any of the configuration's initial targets has a skipped result:

if (configInitialTargets == null || !CheckResults(allResults, configInitialTargets, checkTargetsMissingResults: false, skippedResultsDoNotCauseCacheMiss))
{
    response.Type = ResultsCacheResponseType.NotSatisfied;
}

(skippedResultsDoNotCauseCacheMiss is only true under project isolation.) This has two consequences:

  1. Performance - the project is rescheduled and has to acquire execution time on the node that owns the configuration, only to re-evaluate the same condition and skip again. This is Conditionally skipped targets may lead to bad performance of a build. msbuild#11753, and it currently applies to every Arcade project on every non-Windows build.
  2. Correctness of the error surface - when the configuration is still in flight, the re-entrant request can no longer be served from the node-local results cache, escapes to the scheduler, and is reported as MSB4006: There is a circular dependency in the target dependency graph. This is what broke the dotnet/dotnet source-only build legs ([Operational Issue]: Source-build jobs failing with circular dependency in target dotnet#8275).

Fix

Move the guards from the <Target> element onto the task invocation. The target then always runs and completes successfully, behaving as a no-op when the workaround does not apply, and the results cache stays usable.

This is the same approach as #15743 ("Avoiding InitialTargets altogether here makes sense as it's more performant") and matches ValidateTargetQueues in the Helix SDK, which already puts its condition on the inner task rather than on the target.

A comment is added so the conditions do not get moved back onto the <Target> element.

Validation

Verified against the real Workarounds.targets (not a synthetic copy):

scenario before after
.NET Core MSBuild, re-entrant build of one configuration MSB4006 no error
.NET Framework MSBuild 18.10 (version clause false) task inert task inert, target succeeds, no errors
.NET Framework MSBuild, version clause forced true task executes, sets NetCoreSdkRoot identical

The third case confirms the workaround itself is unchanged on the Windows path it exists for.

Note

Two other conditional InitialTargets exist in the Helix SDK (ValidateOpenQueueUsage, ValidateAzurePipelinesConfiguration). They are left alone here: they are imported by very few projects, so the impact is negligible, and they are unrelated to the regression this PR addresses.

NormalizeNetCoreSdkRootCasing is declared as an InitialTarget on
Workarounds.targets, which aggregates into the InitialTargets of every
project that imports the Arcade SDK. Its condition requires
MSBuildRuntimeType == 'Full', so on non-Windows builds the target is
recorded as TargetResultCode.Skipped.

MSBuild's ResultsCache refuses to satisfy any build request for a
configuration when one of that configuration's initial targets was
skipped (see dotnet/msbuild#11753). The project is therefore rescheduled
instead of being served from the cache, which costs node-wait time in the
common case and turns a re-entrant build of the same configuration into an
MSB4006 "circular dependency" error. The latter broke the dotnet/dotnet
source-only build legs.

Move the guards from the <Target> element onto the task invocation so the
target always completes successfully and behaves as a no-op when the
workaround does not apply. This matches the approach already used by
ValidateTargetQueues in the Helix SDK and by dotnet#15743.

Verified with the real Workarounds.targets:
- .NET Core MSBuild, re-entrant build of one configuration: MSB4006 before,
  clean after.
- .NET Framework MSBuild 18.10 (version clause false): task inert, target
  succeeds, no errors.
- .NET Framework MSBuild with the version clause forced true: the
  NormalizeSdkRootDriveCasing task executes and produces the same
  NetCoreSdkRoot as before the change.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: ff380529-d8b3-4d2d-86b8-ce0ae191bb71
Copilot AI lite review requested due to automatic review settings August 13, 2026 10:28

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.

Pull request overview

This PR adjusts an Arcade SDK workaround InitialTarget so it no longer gets conditionally skipped (and thus recorded as TargetResultCode.Skipped) on non-Windows/non-Full MSBuild runtimes, avoiding MSBuild results-cache misses and preventing re-entrant build requests from surfacing as MSB4006 circular dependency errors.

Changes:

  • Makes NormalizeNetCoreSdkRootCasing target unconditional, moving all guards onto the NormalizeSdkRootDriveCasing task invocation.
  • Updates and expands the in-file documentation to explain why the target must remain unconditional (MSBuild results cache behavior for initial targets).
Show a summary per file
File Description
src/Microsoft.DotNet.Arcade.Sdk/tools/Workarounds.targets Makes the initial target always succeed (no-op when not applicable) to keep MSBuild’s results cache satisfiable and avoid re-entrant scheduling/circular dependency errors.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

@ViktorHofer
ViktorHofer enabled auto-merge (squash) August 13, 2026 10:34
@ViktorHofer
ViktorHofer merged commit 64ce3ee into dotnet:main Aug 13, 2026
9 of 12 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants