Don't forward MSBuild terminal-logger args to the test host (fixes #52114, #52229)#54434
Closed
Evangelink wants to merge 1 commit into
Closed
Don't forward MSBuild terminal-logger args to the test host (fixes #52114, #52229)#54434Evangelink wants to merge 1 commit into
Evangelink wants to merge 1 commit into
Conversation
Fixes #52114 and #52229. With `dotnet test` in MTP mode, options such as `-tl:off` / `--terminalLogger:off` were placed into the test application's argument list and forwarded to the test host process, which rejected them with `Unknown option '--tl'` and produced exit code 5 plus a wall of help output. Adds `LoggerUtility.IsTerminalLoggerArgument` to recognize MSBuild terminal-logger switches (`tl`, `terminalLogger`, `ll`, `livelogger`, `tlp`, `terminalLoggerParameters`) with `-`/`--`/`/` prefixes and `:`/`=` value separators, and updates `MSBuildUtility.GetBuildOptions` to partition unmatched tokens so that those switches reach the build invocation only. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
This was referenced May 25, 2026
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.
Summary
Fixes #52114 and #52229.
Running
dotnet testagainst an MTP test project with an MSBuild terminal-logger switch — for exampledotnet test -tl:offordotnet test --tl:off— currently:--tl, fails withUnknown option '--tl', exits with code 5, and prints its entire help output.So the user sees a wall of noise and the terminal logger remains on during the build.
Fix
Terminal-logger switches are an MSBuild concern. They are added to the MSBuild argument list (alongside the binlog switches that were already routed there) and removed from the test application argument list.
Changes:
LoggerUtility.IsTerminalLoggerArgument— new internal predicate that recognizes:-tl,--tl,/tl,-ll,--ll,/ll,-tlp,--tlp,/tlpterminalLogger,livelogger,terminalLoggerParameterswith the same three prefixes:valueor=value(e.g.-tl:off,--terminalLogger=on,/tlp:default=off)MSBuildUtility.GetBuildOptions— afterSeparateBinLogArguments, partitions the remaining unmatched tokens; terminal-logger tokens are concatenated onto the MSBuild argument sequence, the rest stay as test-application arguments.Design notes
Why a dedicated predicate instead of a full MSBuild argument recognizer?
The bug is reported specifically for terminal-logger switches, and any broader filter would risk silently dropping options the test host legitimately accepts (e.g.
-p:global properties already flow through MSBuild viaOptionValuesToBeForwardedand have a different role on the test-app side). A narrow, well-scoped predicate is also easier to reason about, easier to test, and easier to extend if we find additional MSBuild-only switches leaking in the future.Why colocate the predicate with the binlog logic in
LoggerUtility?It's the same shape of code — recognize an MSBuild diagnostic-output switch so it can be routed correctly — and it lives next to its closest analog,
IsBinLogArgument. Putting it on a hypothetical new helper class would only spread the related concepts across files.Why match
:and=separators?MSBuild accepts both forms on long-name switches (e.g.
-bl:foo.binlogand-bl=foo.binlog). Mirroring that here avoids the predicate disagreeing with how the build invocation will actually parse the same token.Why exact-match (not
StartsWith)?The pre-existing
TerminalLoggerDetector.TryFindin the VSTest path usesStartsWith(prefix + name, ...), which would mis-classify e.g.--terminalLoggerExtraas a terminal-logger switch. The new predicate requires either an exact name match or an immediate:/=separator after the name. The included unit tests pin this down.Alternatives considered
LoggerUtility.SeparateBinLogArgumentsitself. Rejected because that helper is also used fromRunCommand,PublishCommand,PackCommand, andDotNetCommandFactory, and the bug is specific to the MTP test path. Changing the shared helper would either need a new overload or risk subtly affecting other commands.parseResult.UnmatchedTokensbefore MTP parsing. Possible, but the natural seam is alreadyGetBuildOptions, which is the function that builds the two argument lists. Moving the partition there keeps the change local and obvious.-tl. That would mask other genuine "unknown option" mistakes, and would still produce a confusing build experience (terminal logger remains on, which is the user-visible part of the bug).Tests
test/dotnet.Tests/CommandTests/Test/LoggerUtilityTests.cs— 36 cases covering:-/--//prefixes with each of the six terminal-logger names, both bare and with:value/=valueseparators.-tlNoSuchOption,--terminalLoggerExtra,/tlinvalid), missing prefix, too-many-dash prefix, positional argument.All 36 pass locally.