Skip to content

fix(dotnet): rtk dotnet test breaks for projects using global.json MTP mode#1380

Open
danielmarbach wants to merge 4 commits intortk-ai:developfrom
danielmarbach:dotnet-mtp
Open

fix(dotnet): rtk dotnet test breaks for projects using global.json MTP mode#1380
danielmarbach wants to merge 4 commits intortk-ai:developfrom
danielmarbach:dotnet-mtp

Conversation

@danielmarbach
Copy link
Copy Markdown
Contributor

@danielmarbach danielmarbach commented Apr 18, 2026

Fixes #1289

Problem

PR #746 introduced MtpNative mode which injected --report-trx as a direct flag for repos with global.json MTP mode ("test": { "runner": "Microsoft.Testing.Platform" }). This broke xUnit v3 projects with exit code 5:

Unknown option '--report-trx'
Test run completed with non-success exit code: 5

The Altinn/altinn-register repo was affected: .NET 9 SDK, global.json MTP mode, xUnit v3 — no project-file MTP properties at all.

Root cause

--report-trx is not a universal MTP flag. It requires the Microsoft.Testing.Extensions.TrxReport NuGet package which xUnit v3 doesn't bundle (it has --report-xunit-trx instead). MSTest and TUnit bundle it, so it worked for them but failed for xUnit v3.

Verified behavior

All tested with global.json having "test": { "runner": "Microsoft.Testing.Platform" }:

Framework SDK -- --report-trx Direct --report-trx
xUnit v3 3.2.2 .NET 9 ✗ Unknown option ✗ Unknown option
xUnit v3 3.2.2 .NET 10 ✗ Unknown option ✗ Unknown option
MSTest 4.0.2 .NET 9 N/A (MSBuild error)
TUnit 1.36.0 .NET 9 ✓ TRX generated N/A
TUnit 1.36.0 .NET 10 ✓ TRX generated ✓ TRX generated

The xUnit v3 issue reporter confirmed (xunit/xunit#3456) that adding Microsoft.Testing.Extensions.TrxReport NuGet makes --report-trx work universally.

Additionally, -nologo breaks on .NET 10 native MTP with "Unknown option '--nologo'", so it's now skipped for all MTP mode.

Fix

Simplified TestRunnerMode from three variants to two:

  • Classic: VSTest runner → --logger trx --results-directory, -nologo injected
  • MtpAfterSeparator: Any MTP detection (global.json OR project-file) → -- --report-trx, -nologo skipped

Removed MtpNative and MtpGlobalJson. Both global.json MTP and project-file MTP properties now use MtpAfterSeparator, injecting -- --report-trx after the separator.

For xUnit v3 without Microsoft.Testing.Extensions.TrxReport, this produces an informative "Unknown option" error — the user knows to add the package. This is preferable to silently skipping TRX injection, which would regress token savings for the majority of MTP users (MSTest, TUnit) who do bundle TrxReport and benefit from the optimized TRX parsing path. Detecting the NuGet package from csproj/Directory.Build.props/Directory.Packages.props was ruled out as impractical (MSBuild inheritance, central package management).

Test plan

  • xUnit v3 .NET 9 with global.json MTP: -- --report-trx → informative error
  • TUnit .NET 9/10 with global.json MTP: -- --report-trx → TRX generated
  • MSTest .NET 9 with project-file MTP: -- --report-trx → TRX generated
  • -nologo skipped for all MTP mode (verified on .NET 10 native MTP)
  • 1593 unit tests pass

@danielmarbach danielmarbach changed the base branch from master to develop April 18, 2026 13:22
@pszymkowiak pszymkowiak added bug Something isn't working effort-medium 1-2 jours, quelques fichiers labels Apr 18, 2026
@pszymkowiak
Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes global.json MTP detection to use VsTestBridge mode instead of the removed MtpNative mode, which was injecting --report-trx directly and breaking xUnit v3 projects with 'Unknown option' errors. Also skips -nologo for all MTP modes since it breaks on .NET 10 native MTP, and refactors the project file scanning into a separate function.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1289


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@danielmarbach danielmarbach marked this pull request as ready for review April 18, 2026 13:27
@aeppling aeppling added the P2-important Devrait être fixé bientôt label Apr 21, 2026
Copy link
Copy Markdown
Contributor

@F0rty-Tw0 F0rty-Tw0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compatibility matrix in the description made me back off two concerns I'd flagged on first read:

  1. -nologo skip across MTP modes: I worried this was over-conservative, until the .NET 10 native MTP "Unknown option --nologo" repro. Skip is correct.

  2. xUnit v3 "Unknown option" surfacing: initially read as a silent UX downgrade, but the trade-off is conscious. A silent skip would regress token savings for the MSTest/TUnit majority who do bundle TrxReport, and the error is informative once a user knows the package name. NuGet detection from csproj/Directory.Build.props/Directory.Packages.props is impractical for the cited reasons (MSBuild inheritance, central package management), so surfacing the error is the right call.

I also ran a fresh sub-review against .claude/rules/rust-patterns.md and cli-testing.md. Variant deletion is complete: every MtpNative site the diff touches is a removal or rewrite, no residue. The scan_project_files_for_mtp early-return refactor is behavior-preserving (no multi-project regression), and there are no new unwrap() outside tests.

Three small follow-ups follow as inline comments, none blocking.

Open since April 18 with P2-important, three-OS CI green, repro from Altinn/altinn-register. Would be great to see this land.

Comment thread src/cmds/dotnet/dotnet_cmd.rs Outdated
Comment thread src/cmds/dotnet/dotnet_cmd.rs
Comment thread src/cmds/dotnet/dotnet_cmd.rs Outdated
danielmarbach and others added 2 commits May 5, 2026 21:29
…mode

PR rtk-ai#746 introduced MtpNative mode which injected --report-trx directly for
global.json MTP, breaking xUnit v3 projects with 'Unknown option' (exit 5).
--report-trx requires Microsoft.Testing.Extensions.TrxReport which xUnit v3
doesn't bundle (it has --report-xunit-trx instead).

Both global.json MTP and project-file MTP now use MtpVsTestBridge, injecting
-- --report-trx after the separator. This works for MSTest/TUnit which bundle
TrxReport. For xUnit v3 without the extension, the error is informative —
tells users to add the NuGet package (per xunit/xunit#3456).

Also skips -nologo for all MTP mode since it breaks on .NET 10 native MTP.

Fixes rtk-ai#1289
@danielmarbach danielmarbach changed the title fix(dotnet): treat global.json MTP as VsTestBridge instead of native mode fix(dotnet): rtk dotnet test breaks for projects using global.json MTP mode May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-medium 1-2 jours, quelques fichiers P2-important Devrait être fixé bientôt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk dotnet test fails on repositories that use the new testing infrastructure

4 participants