Skip to content

Don't disable the MSBuild server for /mt builds when node reuse is off#14161

Open
AR-May wants to merge 2 commits into
dotnet:mainfrom
AR-May:fix-nodereuse-for-mt
Open

Don't disable the MSBuild server for /mt builds when node reuse is off#14161
AR-May wants to merge 2 commits into
dotnet:mainfrom
AR-May:fix-nodereuse-for-mt

Conversation

@AR-May

@AR-May AR-May commented Jun 25, 2026

Copy link
Copy Markdown
Member

Fixes #14157

Context

When node reuse is disabled (-nr:false), MSBuild refused to use the server node. For a multithreaded ( /mt ) build that's a problem: the server is the only way to get Server GC, which  /mt  builds depend on for performance reasons.

Changes Made

Decouple "may we use the server for this build?" from "may the server stay resident afterward?":

  •  /mt  now uses the server even when node reuse is disabled, purely to obtain Server GC.
  • To honor the no-reuse intent, a new  shutdownServerAfterBuild flag tears the server down immediately after the build completes, so it doesn't persist and each build gets a fresh process.
  • Node reuse being off still disqualifies the server for non- /mt  builds (unchanged behavior).

Testing

Added a unit test.

Copilot AI review requested due to automatic review settings June 25, 2026 08:59

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 MSBuild’s server-engagement logic so that multithreaded (/mt) builds can still run through MSBuild Server (and therefore benefit from Server GC) even when node reuse is disabled (-nr:false / MSBUILDDISABLENODEREUSE=1). It introduces a “shut down after build” behavior to honor the no-reuse intent while still using the server for /mt.

Changes:

  • Decouples “can run on server” from “may keep server resident”: /mt can use server even when node reuse is disabled, with a new shutdownServerAfterBuild flag.
  • Plumbs shutdownServerAfterBuild through XMakeMSBuildClientApp and requests server shutdown after the build completes.
  • Adds a unit test verifying /mt -nr:false uses the server but does not reuse it across builds.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/MSBuild/XMake.cs Computes shutdownServerAfterBuild and allows /mt to engage the server even when node reuse is disabled.
src/MSBuild/MSBuildClientApp.cs Adds a shutdown-after-build option and triggers server shutdown post-build when requested.
src/MSBuild.UnitTests/MSBuildServer_Tests.cs Adds test coverage for /mt server usage + post-build shutdown behavior when node reuse is disabled.

Comment on lines +33 to 35
/// <param name="shutdownServerAfterBuild">Whether to shut the server down once the build completes
/// instead of leaving it resident for reuse.
/// <param name="cancellationToken">Cancellation token.</param>

@AR-May AR-May Jun 25, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is somehting wrong with the git diff? there is </param> at the end of the line in the file. The build is successful as well.

Comment on lines +103 to +106
if (shutdownServerAfterBuild)
{
MSBuildClient.ShutdownServer(CancellationToken.None);
}
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.

MT mode should still use MSBuild Server even when node reuse is disabled

2 participants