Skip to content

Forward terminal logger arguments to MSBuild during dotnet test - #54310

Merged
Evangelink merged 1 commit into
mainfrom
fix/52229-forward-tl-to-msbuild-during-test
May 26, 2026
Merged

Evangelink merged 1 commit into
mainfrom
fix/52229-forward-tl-to-msbuild-during-test

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Fixes #52229.

Problem

When running dotnet test --project Foo.csproj --tl:off against an MTP-based test project, the --tl:off switch is forwarded to the test application instead of to the underlying MSBuild build invocation, causing the test app to fail with Unknown option '--tl'.

Fix

  • Added LoggerUtility.IsTerminalLoggerArgument(string arg) helper to detect MSBuild terminal-logger switches (tl, terminallogger, ll, livelogger, tlp, terminalloggerparameters) with -, --, or / prefixes and an optional :value suffix.
  • Updated MSBuildUtility.GetBuildOptions to extract terminal-logger arguments from parseResult.UnmatchedTokens and route them into MSBuildArgs (forwarded to the build phase) instead of leaving them in TestApplicationArguments. The extraction happens before positional-argument detection so project-path detection is unaffected. This mirrors the existing handling of -bl/--binaryLogger.

Tests

Added test/dotnet.Tests/LoggerUtilityTests.cs:

  • 22 positive-case unit tests covering all prefix/name/colon variants.
  • 10 negative-case unit tests confirming look-alikes (--terminallogger-something, --tlpwithnocolon, -llextra, etc.) are not matched.
  • Integration tests exercising MSBuildUtility.GetBuildOptions end-to-end against the MTP command definition, verifying terminal-logger args are routed to MSBuildArgs and excluded from TestApplicationArguments.
  • Regression test for interspersed positional / test-app / terminal-logger arguments.

Notes

  • Scope is intentionally narrow (terminal-logger args only). Per design review, broader MSBuild passthrough switches (-nodereuse, -graph, etc.) were deliberately not included to avoid intercepting legitimate test-app arguments.
  • Single-dash forms -tl:off, -terminalLogger:auto, -tlp:default=true are still consumed by System.CommandLine as values for the -t short alias of the build target option, so they don't reach unmatched tokens. The user's reported case --tl:off works correctly with this fix; --// forms are also covered.

When running `dotnet test --tl:off` (or other MSBuild terminal-logger
switches) against an MTP-based test project, the argument was being
forwarded to the test application instead of to the underlying MSBuild
build invocation. The test app would then fail with `Unknown option '--tl'`.

Detect terminal-logger arguments (`-tl`, `--terminalLogger`, `-ll`,
`--livelogger`, `-tlp`, `--terminalLoggerParameters` with `-`,
`--`, or `/` prefixes and an optional `:value` suffix) in the
unmatched-tokens list of `MSBuildUtility.GetBuildOptions` and route
them to `MSBuildArgs` instead of `TestApplicationArguments`. This
mirrors the existing handling of `-bl`/`--binaryLogger`.

Fixes #52229.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink
Evangelink requested a review from a team as a code owner May 14, 2026 15:13
Copilot AI review requested due to automatic review settings May 14, 2026 15:13

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

Routes MSBuild terminal-logger switches (--tl, --terminalLogger, --ll, --livelogger, --tlp, --terminalLoggerParameters, with -/--// prefixes) from dotnet test (MTP) to the underlying MSBuild build invocation instead of forwarding them to the test application, fixing #52229.

Changes:

  • Added LoggerUtility.IsTerminalLoggerArgument helper recognizing terminal-logger argument names with -, --, / prefixes and optional :value suffix.
  • In MSBuildUtility.GetBuildOptions, extract terminal-logger args from UnmatchedTokens before positional-argument detection and concatenate them onto MSBuildArgs, mirroring the existing binlog handling.
  • Added LoggerUtilityTests.cs with positive/negative unit tests for the helper plus integration tests confirming the routing through GetBuildOptions.
Show a summary per file
File Description
src/Cli/dotnet/LoggerUtility.cs Adds terminal-logger detection helper with prefix/name tables.
src/Cli/dotnet/Commands/Test/MTP/MSBuildUtility.cs Splits terminal-logger args out of unmatched tokens and forwards them to MSBuild.
test/dotnet.Tests/LoggerUtilityTests.cs Unit + integration tests for the new helper and routing behavior.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 0

Comment thread src/Cli/dotnet/LoggerUtility.cs Resolved

@Evangelink Evangelink left a comment

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.

Expert Review — PR #54310: Forward terminal logger arguments to MSBuild during dotnet test

Reviewed as: Automated expert reviewer (adapted from dotnet/testfx expert-reviewer agent)


Dimension Assessment

# Dimension Status Note
1 Algorithmic Correctness ✅ PASS Logic correctly identifies TL args via exact name match with known prefixes; reverse iteration for removal is safe
2 Threading & Concurrency N/A No shared mutable state; operates on local lists within a synchronous method
3 Security & IPC Contract Safety ✅ PASS No user-controlled paths, no command injection risk — args are forwarded to MSBuild which already validates them
4 Public API & Binary Compatibility N/A All new members are internal static; no public API surface change
5 Performance & Allocations ✅ PASS Not a hot path (called once per dotnet test invocation); allocation of small List<string> is appropriate
6 Cross-TFM Compatibility N/A AsSpan, IndexOf, Equals on spans are all available on the SDK's target framework
7 Resource & IDisposable Management N/A No disposable resources involved
8 Defensive Coding at Boundaries ✅ PASS Handles empty strings, no-colon, colon-with-empty-value gracefully
9 Localization & Resources N/A No user-facing strings added
10 Test Isolation ✅ PASS Tests are stateless; no shared mutable state
11 Assertion Quality ✅ PASS Uses FluentAssertions with descriptive because messages; asserts both inclusion and exclusion
12 Flakiness Patterns ✅ PASS No timing, ports, or filesystem race conditions
13 Test Completeness & Coverage ⚠️ CONCERN See SUGGESTION #1 below
14 Data-Driven Test Coverage ✅ PASS Good mix of positive/negative cases covering all prefixes and names
15 Code Structure & Simplification ✅ PASS Clean, readable; data-driven approach is more maintainable than the existing IsBinLogArgument pattern
16 Naming & Conventions ✅ PASS Follows existing naming (s_ prefix for static fields, Is*Argument pattern)
17 Documentation Accuracy ✅ PASS XML doc comment on IsTerminalLoggerArgument is accurate; inline comment links to issue
18 Analyzer & Code Fix Quality N/A No analyzers changed
19 IPC Wire Compatibility N/A No serialization changes
20 Build Infrastructure & Dependencies N/A No build/dependency changes
21 Scope & PR Discipline ✅ PASS Single concern; linked to issue #52229; no unrelated changes

Findings (prioritized)

SUGGESTION #1 — Missing test for single-dash -tl vs SCL -t alias interaction

The PR description correctly identifies that -tl:off gets consumed by System.CommandLine as a value for the -t short alias and thus never reaches UnmatchedTokens. The IsTerminalLoggerArgument helper would return true for it, but that's harmless since it won't appear in the input.

However, no test explicitly verifies this SCL-consumption behavior. Consider adding a comment or test documenting that single-dash -tl:value forms are correctly handled by SCL before reaching this code, so future maintainers don't wonder about the interaction.

Severity: Low / informational. Not blocking.


SUGGESTION #2 — Duplication with VSTest TerminalLoggerDetector.TryFind

TestCommand.cs:523-547 has an existing TryFind method that matches terminal logger switches using StartsWith (which is subtly less precise — it would match -tlpextra as a hit for tlp). The new IsTerminalLoggerArgument uses exact name matching via Equals which is strictly better.

Consider:

  • In a follow-up, refactoring the VSTest path to reuse LoggerUtility.IsTerminalLoggerArgument, or
  • At minimum, filing a tracking issue for this tech debt.

Not blocking for this PR since the VSTest path is separate and not regressed.


SUGGESTION #3 — = sign as value separator

MSBuild uses : as the switch/value separator (not =). The helper only splits on :, so --tl=on would not be recognized. This is correct behavior since MSBuild itself wouldn't accept = for these switches, but a brief comment explaining this design choice would help future readers who might wonder.


Summary

Clean, well-scoped fix that correctly addresses #52229. The IsTerminalLoggerArgument implementation is more robust than the existing TryFind pattern in the VSTest path (exact name matching vs StartsWith). Test coverage is solid with both unit tests for the helper and integration-style tests for the full GetBuildOptions flow. No blocking or major issues found.


This review was generated by an automated expert reviewer adapted from the dotnet/testfx expert-reviewer agent definition.

Comment thread src/Cli/dotnet/LoggerUtility.cs Resolved
@Evangelink
Evangelink merged commit 5d2edba into main May 26, 2026
29 checks passed
@Evangelink
Evangelink deleted the fix/52229-forward-tl-to-msbuild-during-test branch May 26, 2026 08:32
Evangelink added a commit that referenced this pull request May 27, 2026
Addresses review feedback from PR #54310. The previous TryFind implementation
used StartsWith, which incorrectly matched look-alike switches such as
-tlp:default=true when searching for the name 	l. The returned Switch was
then interpreted by TryFromCommandLine as a terminal logger argument with
value default=true, which failed to parse and yielded
TerminalLoggerMode.Invalid for an otherwise valid -tlp argument.

This change:
- Matches the switch name exactly (the substring before : must equal one of
  the requested names), preventing tlp/lookalike collisions.
- Reorders the prefix iteration so -- is tried before -, ensuring the
  long form wins when both forms appear in the same command line.
- Exposes TryFind and the Switch record as internal so the logic can be
  unit-tested directly via the existing InternalsVisibleTo on dotnet.Tests.

Adds unit tests covering positive recognition, the tlp/lookalike regression,
explicit tlp recognition, long-form preference, and the no-match case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone May 27, 2026
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.

[MTP] Cannot switch off terminal logger when building during dotnet test

3 participants