Repository navigation
Forward terminal logger arguments to MSBuild during dotnet test - #54310
Conversation
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>
There was a problem hiding this comment.
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.IsTerminalLoggerArgumenthelper recognizing terminal-logger argument names with-,--,/prefixes and optional:valuesuffix. - In
MSBuildUtility.GetBuildOptions, extract terminal-logger args fromUnmatchedTokensbefore positional-argument detection and concatenate them ontoMSBuildArgs, mirroring the existing binlog handling. - Added
LoggerUtilityTests.cswith positive/negative unit tests for the helper plus integration tests confirming the routing throughGetBuildOptions.
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
Evangelink
left a comment
There was a problem hiding this comment.
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 | 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.
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>
Fixes #52229.
Problem
When running
dotnet test --project Foo.csproj --tl:offagainst an MTP-based test project, the--tl:offswitch is forwarded to the test application instead of to the underlying MSBuild build invocation, causing the test app to fail withUnknown option '--tl'.Fix
LoggerUtility.IsTerminalLoggerArgument(string arg)helper to detect MSBuild terminal-logger switches (tl,terminallogger,ll,livelogger,tlp,terminalloggerparameters) with-,--, or/prefixes and an optional:valuesuffix.MSBuildUtility.GetBuildOptionsto extract terminal-logger arguments fromparseResult.UnmatchedTokensand route them intoMSBuildArgs(forwarded to the build phase) instead of leaving them inTestApplicationArguments. 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:--terminallogger-something,--tlpwithnocolon,-llextra, etc.) are not matched.MSBuildUtility.GetBuildOptionsend-to-end against the MTP command definition, verifying terminal-logger args are routed toMSBuildArgsand excluded fromTestApplicationArguments.Notes
-nodereuse,-graph, etc.) were deliberately not included to avoid intercepting legitimate test-app arguments.-tl:off,-terminalLogger:auto,-tlp:default=trueare still consumed by System.CommandLine as values for the-tshort alias of the build target option, so they don't reach unmatched tokens. The user's reported case--tl:offworks correctly with this fix;--//forms are also covered.