Don't disable the MSBuild server for /mt builds when node reuse is off - #14248
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts MSBuild Server routing so /mt builds can still run on the MSBuild Server even when node reuse is disabled (-nr:false), preserving the performance benefit of Server GC while honoring the “no reuse” intent by shutting the server down immediately after the build.
Changes:
- Decouples “can host build on server” from “can keep server resident,” allowing
/mt+-nr:falseto use the server but request post-build teardown. - Plumbs a new
shutdownServerAfterBuild/ShutdownAfterBuildflag from CLI parsing → client → IPC packet → server shutdown behavior. - Adds unit test coverage for the new packet field and an end-to-end test for
/mt+-nr:false.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/MSBuild/XMake.cs | Computes shutdownServerAfterBuild during the authoritative command-line parse and passes it to the server client path. |
| src/MSBuild/MSBuildClientApp.cs | Extends the server client execution entrypoints to pass the shutdown-after-build intent through. |
| src/Build/BackEnd/Client/MSBuildClient.cs | Stores and sends shutdown intent on ServerNodeBuildCommand. |
| src/Build/BackEnd/Node/ServerNodeBuildCommand.cs | Adds ShutdownAfterBuild field to the server build-command packet and serializes it. |
| src/Build/BackEnd/Node/OutOfProcServerNode.cs | Honors ShutdownAfterBuild by exiting after the build instead of returning to reuse mode. |
| src/MSBuild.UnitTests/MSBuildServer_Tests.cs | Adds E2E test that /mt -nr:false uses the server but does not leave it resident. |
| src/Build.UnitTests/BackEnd/ServerNodeBuildCommand_Tests.cs | Adds round-trip serialization test for the new packet field. |
| documentation/MSBuild-Server.md | Documents server lifetime behavior when node reuse is disabled, including the /mt exception. |
AR-May
marked this pull request as ready for review
July 2, 2026 10:13
JanProvaznik
approved these changes
Jul 2, 2026
OvesN
approved these changes
Jul 3, 2026
JanProvaznik
added a commit
to JanProvaznik/msbuild
that referenced
this pull request
Jul 8, 2026
Resolves conflicts with dotnet#14248 ("Don't disable the MSBuild server for /mt builds when node reuse is off"), which introduced the short-lived server (a /mt build with node reuse off uses the server for Server GC but tears it down after the build via ServerNodeBuildCommand.ShutdownAfterBuild). - CanRunServerBasedOnCommandLineSwitches: integrate dotnet#14248's shutdownServerAfterBuild and the new node-reuse gate (nodeReuseDisqualifies = !nodeReuse && !multiThreaded) with my serverDisabledReason/reasonCode outputs. The node-reuse-disabled reason now only fires for non-/mt builds (a /mt build uses a short-lived server instead). - MSBuildServerLifecycleEventArgs gains a ShortLived flag (serialized in the v27 record and node packets). XMake sets it for a spawned server that will shut down afterward, and logs a distinct "spawned (short-lived)" message. The flag is surfaced from OutOfProcServerNode.CurrentBuildShutsDownServerNode (additive; the public BuildCallback delegate is left unchanged to avoid an API break). - New MSBuildServerNodeSpawnedShortLived resource (+ xlf); docs updated. - Tests: round-trip covers ShortLived; new e2e ServerShortLivedForMultithreadedWhenNodeReuseOff. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Sep 10, 2026
This was referenced Sep 11, 2026
Closed
Merged
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?":
shutdownServerAfterBuildflag tears the server down immediately after the build completes, so it doesn't persist and each build gets a fresh process.Testing
Added a unit test.
Notes
Previous attempt: #14161. It tries to shut down the server after the build by issuing a shutdown command. However, previous implementation does not guarantee that the server will not accept another client's request in the meantime and subsequently fail to shut down. Another option would be to re-parse the command line and identify cases where a server shutdown is required, but I would prefer the initial parsing to remain the single source of truth and avoid re-parsing. Client and server are the same handshake-gated MSBuild version, so there's no cross-version serialization concern over the communication protocol.