Repository navigation
C#: Disable MSBuild node reuse and the MSBuild server during tracing - #23254
Open
michaelnebel wants to merge 2 commits into
Open
michaelnebel wants to merge 2 commits into
michaelnebel wants to merge 2 commits into
Conversation
michaelnebel
force-pushed
the
michaelnebel-csharp-extractor-env-vars
branch
from
November 26, 2026 10:14
beaab02 to
8e3dbef
Compare
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the MSBuild tracing reliability changes.
No open issues 🎉
What changed in this PR
This PR improves C# traced extraction reliability, including for .NET 11, by disabling MSBuild server use and node reuse through extractor environment settings.
Changes:
- Disable MSBuild server use and node reuse without adding flags incompatible with older .NET versions.
- Extend integration coverage across
dotnet build,msbuild,publish, andpack, checking both environment settings. - Add a change note describing the reliability improvement.
| File | Description |
|---|---|
| csharp/ql/lib/change-notes/2026-11-26-msbuild-tracing.md | Documents the tracing reliability fix. |
| csharp/ql/integration-tests/all-platforms/dotnet_build/test.py | Tests four build commands with the environment-check target. |
| csharp/ql/integration-tests/all-platforms/dotnet_build/dotnet_build.csproj | Adds assertions for both environment settings. |
| csharp/codeql-extractor.yml | Sets environment variables to disable MSBuild server use and node reuse. |
Review effort: Balanced (adaptive)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
michaelnebel
force-pushed
the
michaelnebel-csharp-extractor-env-vars
branch
from
November 26, 2026 14:00
8e3dbef to
2b973cd
Compare
Contributor
Author
Great. Will do some more testing before merging. |
This branch has not been deployed
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.
In this PR we set some environment variables that affects
dotnetwhen building code and thus affects traced extraction. This is needed to support traced extraction of .NET 11 as MSBuild server is now enabled by default (see here).Some context:
dotnetmight use existing servers or workers when building code (using MSBuild) and we need to prevent this, otherwise traced extraction might fail as the calls might not be intercepted. The different servers and workers:/p:UseSharedCompilation=false. This is the "best" solution for overriding in build commands as it also overrides existing settings.DOTNET_CLI_USE_MSBUILD_SERVER=false. Prior to .NET 11, the default wasfalsebut for .NET 11 the default istrue. That is, if we want to do traced extraction for .NET 11 we need to disable the MS Build server.dotnetmight re-use for building code, but we haven't observed any problems with this. We can disable these by settingMSBUILDDISABLENODEREUSE=1(this should also implicitly disable the MSBuild server).Preferably, we would like to disable the use of MSBuild Server and MSBuild workers by injecting a flag into the build command (as this would also override build commands that could override the setting of an environment variable). The options are
--disable-build-servers: This should handle all cases mentioned above, but it was introduced in .NET 7 and previous versions of .NET fails withMSB1001: Unknown switch, which means that we would break builds for .NET 6 and earlier. So we can't use that unless we narrow traced support to .NET 7 or newer.-nodeReuse:false: This would disable MSBuild Server and workers, but fails for .NET 2 Core and earlier. We could consider removing .NET Core 2 and earlier for the listed of supported .NET variants.AFAIK, there we can't detect the
dotnetversion we are tracing, which leaves us with the only option of setting the environment variables for the process that invokes the extractor.Testing