Skip to content

Support --use-current-runtime / --ucr on dotnet test (MTP)#53515

Open
Copilot wants to merge 5 commits intorelease/10.0.3xxfrom
copilot/add-current-runtime-option-dotnet-test
Open

Support --use-current-runtime / --ucr on dotnet test (MTP)#53515
Copilot wants to merge 5 commits intorelease/10.0.3xxfrom
copilot/add-current-runtime-option-dotnet-test

Conversation

Copy link
Contributor

Copilot AI commented Mar 18, 2026

dotnet test lacked --use-current-runtime (--ucr) support despite it being available on dotnet build, publish, restore, and store. This change adds support for the MTP code path.

Changes

  • TestCommandDefinition.MicrosoftTestingPlatform — replaced standalone PropertiesOption with ImplicitRestoreOptions = new(showHelp: false, useShortOptions: false), calling ImplicitRestoreOptions.AddTo(Options) exactly as BuildCommandDefinition does. This provides --ucr/--use-current-runtime (visible in help) along with the other hidden restore pass-through options.
  • Snapshot (MTPHelpSnapshotTests.VerifyMTPHelpOutput.verified.txt) — updated to reflect the new option in MTP help output.
dotnet test --use-current-runtime
dotnet test --ucr
# both produce: --property:UseCurrentRuntimeIdentifier=True
Original prompt

This section details on the original issue you should resolve

<issue_title>Support --use-current-runtime on dotnet test commands</issue_title>
<issue_description>### Is your feature request related to a problem? Please describe.

In general, where -r is supported, I would expect --arch, --os, and --use-current-runtime and their variants to also be supported.

--ucr is available in the CommonOptions.</issue_description>

Comments on the Issue (you are @copilot in this section)

@Youssef1313 For VSTest, I think this might be tricky to implement and get right (@nohwnd?). But it hopefully should be okay to implement for MTP. I feel like `dotnet test` for MTP should actually use `AddImplicitRestoreOptions` similar to `dotnet build`? But we need to carefully review all the options there. Note that for MTP, I expect that nothing is needed other than really adding the command line option and the forwarding to `UseCurrentRuntimeIdentifier` should do its job as normal.

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Copilot AI changed the title [WIP] Support --use-current-runtime on dotnet test commands Support --use-current-runtime / --ucr on dotnet test Mar 18, 2026
Copilot AI requested a review from Youssef1313 March 18, 2026 13:32
@Youssef1313
Copy link
Member

@copilot Do not change anything for VSTest. For MTP, use AddImplicitRestoreOptions similar to how BuildCommand do it.

…evert VSTest changes

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 18, 2026

@copilot Do not change anything for VSTest. For MTP, use AddImplicitRestoreOptions similar to how BuildCommand do it.

Done in 9176c9f. VSTest changes are reverted. For MTP, replaced the standalone UseCurrentRuntimeOption with ImplicitRestoreOptions = new(showHelp: false, useShortOptions: false) and called ImplicitRestoreOptions.AddTo(Options) exactly like BuildCommandDefinition does — this provides --ucr/--use-current-runtime (along with the other hidden restore pass-through options).

…tion to preserve original option ordering

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
… line

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 19, 2026

@copilot Do not change anything for VSTest. For MTP, use AddImplicitRestoreOptions similar to how BuildCommand do it.

Done — no VSTest changes. For MTP, ImplicitRestoreOptions = new(showHelp: false, useShortOptions: false) replaces the standalone PropertiesOption, and ImplicitRestoreOptions.AddTo(Options) is called after ArtifactsPathOption (same pattern as BuildCommandDefinition).

public readonly Option<IReadOnlyDictionary<string, string>> EnvOption = CommonOptions.CreateEnvOption();

public readonly Option<ReadOnlyDictionary<string, string>?> PropertiesOption = CommonOptions.CreatePropertyOption();
public readonly ImplicitRestoreOptions ImplicitRestoreOptions = new(showHelp: false, useShortOptions: false);
Copy link
Member

Choose a reason for hiding this comment

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

Revisiting this again, many options are marked as hidden (because showHelp is false).

I don't have the context on why this was introduced. Are these some options that are kept only for backcompat but we are no longer interested in? So should I avoid using them for MTP dotnet test?

@baronfel Can you please advise here?

@Youssef1313 Youssef1313 marked this pull request as ready for review March 19, 2026 12:32
Copilot AI review requested due to automatic review settings March 19, 2026 12:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds --use-current-runtime (--ucr) support to the Microsoft Testing Platform (MTP) code path for dotnet test, aligning it with other CLI commands that already forward this switch to MSBuild.

Changes:

  • Replaced the standalone PropertiesOption in the MTP dotnet test command definition with ImplicitRestoreOptions (matching dotnet build), which introduces --ucr/--use-current-runtime forwarding.
  • Updated the MTP help snapshot to include the new option in dotnet test help output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Cli/Microsoft.DotNet.Cli.Definitions/Commands/Test/TestCommandDefinition.MicrosoftTestingPlatform.cs Uses ImplicitRestoreOptions so MTP dotnet test includes --ucr/--use-current-runtime and other restore passthrough options.
test/dotnet.Tests/CommandTests/Test/snapshots/MTPHelpSnapshotTests.VerifyMTPHelpOutput.verified.txt Updates the verified help output snapshot to reflect the newly visible --ucr option.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 150 to 156
TargetPlatformOptions.AddTo(Options);
Options.Add(VerbosityOption);
Options.Add(NoRestoreOption);
Options.Add(NoBuildOption);
Options.Add(ArtifactsPathOption);
ImplicitRestoreOptions.AddTo(Options);
Options.Add(NoAnsiOption);
Copy link
Member

@nohwnd nohwnd left a comment

Choose a reason for hiding this comment

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

read the suggestion from copilot backwards, probably good idea to block also --ucr when using --test-modules, because that deals with already built artifacts.

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.

4 participants