Skip to content

fix(dotnet): TRX injection for Microsoft.Testing.Platform projects#746

Merged
aeppling merged 1 commit intortk-ai:developfrom
danielmarbach:dotnet-test
Mar 21, 2026
Merged

fix(dotnet): TRX injection for Microsoft.Testing.Platform projects#746
aeppling merged 1 commit intortk-ai:developfrom
danielmarbach:dotnet-test

Conversation

@danielmarbach
Copy link
Copy Markdown
Contributor

@danielmarbach danielmarbach commented Mar 20, 2026

Summary

Closes #572. rtk dotnet test was injecting --logger trx --results-directory (VSTest flags) into projects using Microsoft.Testing.Platform (MTP), causing test runs to fail or produce no output. A previous attempt to fix this (PR #745) removed all TRX injection for MTP projects, which was overly conservative — modern MTP frameworks (TUnit 1.19.74+, MSTest, xUnit with MTP runner) include Microsoft.Testing.Extensions.TrxReport natively, so --report-trx works fine.

Detect the test runner mode from project files and global.json, then inject the appropriate TRX flag per mode:

Mode Detection Injected flags
Classic (VSTest) No MTP properties in csproj --logger trx --results-directory
MtpVsTestBridge UseMicrosoftTestingPlatformRunner, UseTestingPlatformRunner, or TestingPlatformDotnetTestSupport in project file -- --report-trx (after -- separator, reaches MTP runtime)
MtpNative "test": {"runner": "Microsoft.Testing.Platform"} in global.json --report-trx (direct flag, .NET 10 native mode)

Detection priority: global.json (MtpNative) > project-file properties (MtpVsTestBridge) > Classic. --nologo is skipped for MtpNative since args go directly to the MTP runtime, not MSBuild.

Notes

  • VsTestBridge on .NET 10: microsoft.testing.platform.msbuild 2.x blocks the legacy VSTest path on .NET 10 SDK. Users on .NET 10 should use global.json MTP native mode. VsTestBridge remains supported for .NET 9 SDK and earlier.
  • TRX file location: In MtpNative mode, TRX files land in bin/Debug//TestResults/ instead of ./TestResults. The existing ./TestResults fallback scanner still picks up user-placed TRX files.
  • No framework-specific detection: --report-trx is injected for all MTP projects without checking for specific packages — modern MTP frameworks ship TrxReport natively.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test

  • Manual testing: rtk <command> output inspected

    • Unit tests for all three mode detection paths (77 dotnet tests, 1051 total)
    • scan_mtp_kind_in_file covers all three MTP properties
    • inject_report_trx_into_args inserts after existing -- separator or appends -- --report-trx
    • Double-injection guard (has_report_trx_arg)
    • global.json walk-up detection
    • Directory.Build.props walk-up detection
    • Dogfooded with TUnit 1.19.74 on .NET 10: MtpNative mode passes, TRX file created at bin/Debug/net10.0/TestResults/*.trx, exit code propagated correctly

Important: All PRs must target the develop branch (not master).
See CONTRIBUTING.md for details.

@danielmarbach danielmarbach changed the title Dotnet test Fix trx injection for dotnet tests running with various Microsoft Testing Platfform modes Mar 20, 2026
@danielmarbach danielmarbach changed the base branch from master to develop March 20, 2026 10:17
@danielmarbach danielmarbach changed the title Fix trx injection for dotnet tests running with various Microsoft Testing Platfform modes fix(dotnet): restore TRX injection for Microsoft.Testing.Platform projects Mar 20, 2026
@danielmarbach danielmarbach changed the title fix(dotnet): restore TRX injection for Microsoft.Testing.Platform projects fix(dotnet): TRX injection for Microsoft.Testing.Platform projects Mar 20, 2026
@danielmarbach danielmarbach marked this pull request as ready for review March 20, 2026 10:23
@aeppling aeppling self-assigned this Mar 20, 2026
@aeppling
Copy link
Copy Markdown
Contributor

aeppling commented Mar 20, 2026

Useless ending 'if' in detect_test_runner_mode

In your function detect_test_runner_mode()
You check at the beginning
if is_global_json_mtp_mode() {
return TestRunnerMode::MtpNative;
}

Then at the end again same, which is never reached

Should be ready to merge

Thanks for this clean contribution, safe fallback on mixed projects, and clean code.

Thanks for you contribution !

On merge

close: #572

@danielmarbach
Copy link
Copy Markdown
Contributor Author

@aeppling are you addressing it (PR has push rights) or do you want me to?

@aeppling
Copy link
Copy Markdown
Contributor

could you trigger ci tests on your side please ? then we will merge once passed
you can push empty commit to trigger

i do not see historical run of those, should run benchmark, clippy, and so on

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 20, 2026

CLA assistant check
All committers have signed the CLA.

@danielmarbach
Copy link
Copy Markdown
Contributor Author

Cla signed

@danielmarbach
Copy link
Copy Markdown
Contributor Author

Useless ending 'if' in detect_test_runner_mode

In your function detect_test_runner_mode() You check at the beginning if is_global_json_mtp_mode() { return TestRunnerMode::MtpNative; }

Then at the end again same, which is never reached

Should be ready to merge

Thanks for this clean contribution, safe fallback on mixed projects, and clean code.

Thanks for you contribution !

On merge

close: #572

Addressed

…ting Platfform modes

Signed-off-by: Daniel Marbach <danielmarbach@users.noreply.github.com>
@aeppling aeppling merged commit 8eefef1 into rtk-ai:develop Mar 21, 2026
10 checks passed
@aeppling
Copy link
Copy Markdown
Contributor

Thanks for the contribution !

@danielmarbach danielmarbach mentioned this pull request Mar 23, 2026
@danielmarbach danielmarbach deleted the dotnet-test branch April 18, 2026 11:32
danielmarbach added a commit to danielmarbach/rtk that referenced this pull request Apr 18, 2026
…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
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.

3 participants