Skip to content

Enable -nodeReuse in the VMR pipeline - #9410

Merged
ViktorHofer merged 16 commits into
mainfrom
msbuild-mt-nodereuse-test-build
Sep 18, 2026
Merged

ViktorHofer merged 16 commits into
mainfrom
msbuild-mt-nodereuse-test-build

Conversation

@ViktorHofer

@ViktorHofer ViktorHofer commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Enables MSBuild node reuse for VMR repo builds, plus the fixes that unblock it.

  • Node reuse on. -nodeReuse 1 is added to baseArguments, and the DotNetBuildNodeReuse → CommonArgs logic moves from repo-projects/Directory.Build.props to Directory.Build.targets so it can see ForceDotNetMSBuildEngine. It stays off for repos built with VS MSBuild: both engines spawn .NET task hosts from the same bootstrapped SDK and the task host handshake is salted with the task host's own tools directory, so a VS MSBuild parent can adopt a pooled task host started by an SDK MSBuild parent and then fail to deserialize its reply (MSB4217). Fixed task-host-side by Own sidecar TaskHosts so they cannot outlive their owner msbuild#14584; the carve-out can go once the bootstrapped SDK carries that fix (Node reuse lets a .NET task host be adopted by a different-version parent, corrupting TaskHostTaskComplete (MSB4217) msbuild#15062).
  • Roslyn no longer substs T: in the VMR. The subst is process-wide state that outlives the build, so a reused node keeps writing to a T: that no longer exists and fails with MSB6003. This is the root-cause fix for the previous workaround, so the per-repo MSBUILDNODEHANDSHAKESALT and the MSBUILDNODECONNECTIONTIMEOUT=90000 env vars are removed and nodes are shareable across repo builds again.
  • Per-repo build timeout (RepoBuildTimeoutMinutes, 150 in CI). A hung repo build used to run into the job timeout, which cancels the job and skips log collection. A timed-out Exec kills the build process tree and fails the target instead, so the OnError targets still publish the partial logs. Opt-in: no timeout when the property is unset.
  • Logs survive cancellation. Two succeededOrFailed() → always() conditions so BuildLogs is still collected and published when a job is canceled or times out. Also drops the unused MSBuildDebugPathTargetDir; MSBUILDDEBUGPATH is unchanged.

Build times

Duration of the Build step in this PR's build, against the average of the 7 most recent successful main builds (minutes):

Vertical main avg (n=7) PR Δ
Android_Shortstack_arm64 40.8 30.7 −24.8%
Browser_Shortstack_wasm 74.4 65.4 −12.1%
Windows_x64 120.6 107.3 −11.0%
Windows_x86 85.7 76.7 −10.5%
Ubuntu2404_Ubuntu_BuildTests_x64 85.1 79.6 −6.5%
SB_CentOSStream10_Online_MsftSdk_x64 42.5 39.8 −6.4%
SB_CentOSStream10_Offline_CurrentSourceBuiltSdk_x64 43.3 40.7 −6.0%
iOSSimulator_Shortstack_arm64 * 94.4 117.2 +24.2%

On all seven stable verticals the PR is faster than every one of the 7 main builds, so the win is outside normal run-to-run variance.

* iOSSimulator_Shortstack_arm64 swings between 84.3 and 111.4 minutes on main (32% spread, vs ≤8.6% for every other vertical), so its number here is agent noise rather than a regression.

Do not merge. Adds -mt 1 and -nodeReuse 1 to baseArguments so a CI test
build exercises MSBuild's multi-threaded mode and node reuse across all
verticals.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
Copilot AI lite review requested due to automatic review settings September 16, 2026 08:11
@ViktorHofer
ViktorHofer requested review from a team as code owners September 16, 2026 08:11
@azure-pipelines

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

@ViktorHofer

Copy link
Copy Markdown
Member Author

/azp run dotnet-unified-build-full

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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.

Copilot review overview

🟡 Changes recommended

-mt 1 may break unmigrated wrappers, and -nodeReuse 1 is not honored by some dependencies.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Enables MSBuild multithreading and node reuse in VMR CI builds.

Changes:

  • Adds -mt 1 and -nodeReuse 1 to shared build arguments.
  • Applies them across VMR build and test invocations.
File Summary
eng/​pipelines/​templates/​jobs/​vmr-build.yml Enables the MSBuild options; wrapper compatibility issues require changes before approval.

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

@ViktorHofer
ViktorHofer marked this pull request as draft September 16, 2026 12:10
Added extra debugging option to baseArguments in vmr-build.yml.
@ViktorHofer

Copy link
Copy Markdown
Member Author

/azp run dotnet-unified-build-full

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

ViktorHofer and others added 2 commits September 16, 2026 18:04
Roslyn's build substitutes T: as the process-wide TEMP directory and removes
the substitution on exit. In the VMR, MSBuild nodes are reused across
concurrently building repos, so a node that picks up T: keeps using it after
the roslyn build tears it down, failing with MSB6003 in whichever repo reuses
that node.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 1a253860-f2e5-4806-b72d-6f2efac9805c
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team September 16, 2026 16:17
@ViktorHofer

Copy link
Copy Markdown
Member Author

/azp run dotnet-unified-build-full

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@ViktorHofer

Copy link
Copy Markdown
Member Author

/azp run dotnet-unified-build-full

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

ViktorHofer and others added 8 commits September 16, 2026 23:31
Restore /p:EnableExtraDebugging=true so MSBUILDDEBUGCOMM traces and
'MSBuild_*.failure.txt' are produced again. They land in
MSBUILDDEBUGPATH, which repo-projects sets to the per-repo log dir
(artifacts/log/<config>/<repo>), and the pipeline already publishes all
of artifacts/log - so they end up in the BuildLogs artifact. Needed to
diagnose the MSB4217 'task host node exited prematurely' failures in the
Windows legs.

MSBuildDebugPathTargetDir (artifacts/msbuild-debug) was only ever passed
to MakeDir: nothing pointed MSBUILDDEBUGPATH at it, nothing wrote to it,
and artifacts/msbuild-debug isn't published. Remove it.

Co-authored-by: Copilot <[email protected]>
A repo build that hangs let the AzDO job run into its own timeout. A canceled
job skips the "Copy logs to BuildLogs staging" step, so the published BuildLogs
artifact came back empty and there was nothing to diagnose.

Cap a single repo build via Exec's Timeout (150 minutes; the longest repo,
runtime, takes ~80). On expiry MSBuild kills the whole build process tree and
fails the target, which runs the existing OnError targets, so MoveDotNetBuildLogs
still moves the hung repo's partial logs into artifacts/log and the job fails
normally instead of being canceled.

Also switch the log staging and BuildLogs publish steps to always() so a genuine
cancellation still collects whatever has been written so far.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 9e7e5da7-45e2-4e3e-a93b-05e89821a39c
EnableExtraDebugging turns on a set of MSBuild debug switches that are far too
expensive for a default CI run. MSBUILDDEBUGSCHEDULER makes the scheduler write
its full state to disk synchronously after every scheduling pass; in build
1600472 that produced a 2.6 GB SchedulerState_*.txt for runtime, on the
scheduler's critical path. MSBUILDDEBUGFORCECACHING, MSBUILDDEBUGEVALUATION and
MSBUILDLOGTASKINPUTS are similarly costly. Together they slowed the runtime
build enough to change the failure mode from a fast MSB4217 into a timeout,
which makes it useless as a diagnostic baseline.

Split out EnableMSBuildCommTracing, which only sets MSBUILDDEBUGCOMM and
produces the MSBuild_CommTrace_PID_*.txt node handshake/connect/reuse traces.
That is all the node reuse and task host investigation needs. The pipeline now
passes that instead; EnableExtraDebugging still implies it and keeps the heavy
switches for targeted local or CI runs.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 9e7e5da7-45e2-4e3e-a93b-05e89821a39c
Both MSBuild engines spawn their .NET task hosts from the same bootstrapped
SDK, and the task host handshake is salted with the task host's own tools
directory rather than the parent's. That salt is therefore identical for a VS
MSBuild parent and an SDK MSBuild parent, so a VS parent can adopt a pooled
task host that an SDK parent started. The adopted host keeps the packet version
of the parent that launched it and serializes its reply at that layout, which
the new parent fails to deserialize and reports as MSB4217.

Only aspnetcore and wpf build with VS MSBuild, and only on Windows, so the rest
of the repos keep node reuse. dotnet/msbuild#14584 fixes the task host side;
this carve-out can be removed once the bootstrapped SDK carries that fix.

The node reuse arguments move from Directory.Build.props to
Directory.Build.targets because ForceDotNetMSBuildEngine is set in the repo
project body, which has not been evaluated yet when the props file is imported.

See dotnet/msbuild#15062.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 9e7e5da7-45e2-4e3e-a93b-05e89821a39c
Removed MSBuild communication tracing settings and related comments to streamline build configuration.
@ViktorHofer ViktorHofer changed the title Enable -mt and -nodeReuse in the VMR pipeline Enable -nodeReuse in the VMR pipeline Sep 18, 2026
@ViktorHofer
ViktorHofer marked this pull request as ready for review September 18, 2026 11:21
@azure-pipelines

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

@ViktorHofer

Copy link
Copy Markdown
Member Author

/azp run dotnet-unified-build-full

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@ViktorHofer
ViktorHofer merged commit 1c1ae5d into main Sep 18, 2026
55 of 64 checks passed
@ViktorHofer
ViktorHofer deleted the msbuild-mt-nodereuse-test-build branch September 18, 2026 13:24
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