Skip to content

Add XUnitVersion v3 option (MTP default) to xunit templates - #54636

Merged
Evangelink merged 6 commits into
dotnet:mainfrom
Evangelink:dev/amauryleve/xunit-template-v3-option
Jun 9, 2026
Merged

Evangelink merged 6 commits into
dotnet:mainfrom
Evangelink:dev/amauryleve/xunit-template-v3-option

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Partial fix for #54499.

Adds an opt-in xUnit v3 path to the built-in xunit templates (C#/F#/VB) while keeping xUnit v2 as the default (no change for existing users).

What this adds

  • New --xunit-version choice option on dotnet new xunit with values v2 (default) and v3.
  • New --test-runner choice option, only meaningful when --xunit-version v3 is used. Defaults to Microsoft.Testing.Platform; VSTest is the alternative.

Behavior

Command Result
dotnet new xunit Unchanged: xUnit v2 + Microsoft.NET.Test.Sdk + xunit.runner.visualstudio + coverlet.collector.
dotnet new xunit --xunit-version v3 xUnit v3 with MTP as the runner. Project gets OutputType=Exe, UseMicrosoftTestingPlatformRunner=true, references xunit.v3.mtp-v2, includes a xunit.runner.json file, and a post-action creates/updates global.json with the runner property. Shape mirrors the official xunit.net v3 template.
dotnet new xunit --xunit-version v3 --test-runner VSTest xUnit v3 via VSTest: Microsoft.NET.Test.Sdk + xunit.v3.mtp-off + xunit.runner.visualstudio + xunit.runner.json.

Files changed

For each of the C#, F#, and VB xunit templates under template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/:

  • .template.config/template.json — added XUnitVersion and TestRunner choice symbols, sources modifier to exclude xunit.runner.json outside v3, and an addJsonProperty post-action gated on v3+MTP.
  • Project file (csproj/fsproj/vbproj) — conditional v2/v3 shape.
  • Test source — added Assert.True(true) body when v3 (so the generated project has at least one passing test).
  • .template.config/dotnetcli.host.json — --xunit-version and --test-runner CLI aliases.
  • .template.config/ide.host.json — symbolInfo entries with shared persistence.
  • .template.config/localize/templatestrings.en.json — English localization for the new symbols (other languages will be filled in by the loc pipeline, matching the recent MSTest TestRunner addition).
  • New xunit.runner.json per language template.

Tests:

  • test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs — added XUnitV3ProjectTemplate_WithTestRunner_CanBeInstalledAndTestsArePassing theory covering 3 languages × 2 runners.

Validation

  • New theory: 6/6 passing (csharp/fsharp/vb × MTP/VSTest).
  • Existing ProjectTemplate_CanBeInstalledAndTestsArePassing for xunit (default v2): 3/3 passing — no regression.

Out of scope (intentionally)

  • xUnit v3 is not made the default (issue discussion suggests a phased opt-in first).
  • No related package version bumps.
  • Non-English templatestrings.*.json files are not updated by hand — same pattern used for the recent MSTest TestRunner symbol; OneLocBuild fills them in.

Copilot AI review requested due to automatic review settings June 8, 2026 12:48
@Evangelink
Evangelink requested review from a team as code owners June 8, 2026 12:49
)

Add a new XUnitVersion choice parameter (v2 default, v3 opt-in) and a
TestRunner choice parameter (Microsoft.Testing.Platform default,
VSTest available) to the C#, F#, and VB xunit templates.

For the v3 path:
- Mirror the official xunit.net v3 project shape, including a
  xunit.runner.json file copied to the output.
- With MTP (default): emit OutputType=Exe,
  UseMicrosoftTestingPlatformRunner=true, reference xunit.v3.mtp-v2,
  and create/update a global.json with the test runner property.
- With VSTest: reference Microsoft.NET.Test.Sdk, xunit.v3.mtp-off, and
  xunit.runner.visualstudio.

The v2 default path is preserved verbatim for backwards compatibility.

Also adds dotnet new CLI aliases (--xunit-version, --test-runner), IDE
symbolInfo entries, en localization, and integration tests covering all
3 languages x 2 runners.

Co-authored-by: Copilot <[email protected]>
@Evangelink
Evangelink force-pushed the dev/amauryleve/xunit-template-v3-option branch from f494bf3 to da3b3e5 Compare June 8, 2026 12:51

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

This PR adds an opt-in xUnit v3 path (with runner selection) to the built-in xunit templates, and also introduces a new two-stage Ctrl+C cancellation/force-exit implementation for dotnet test when using the Microsoft Testing Platform (including localized UX text and new tests).

Changes:

  • Add --xunit-version (v2|v3) and --test-runner (Microsoft.Testing.Platform|VSTest) options to the C#/F#/VB xUnit templates, including conditional package/project shape and xunit.runner.json.
  • Add template integration coverage for xUnit v3 across languages and runner options.
  • Add Ctrl+C cancellation manager for MTP dotnet test orchestration (cooperative cancel on first Ctrl+C; force-kill + exit code on second Ctrl+C), plus localization updates.
Show a summary per file
File Description
test/dotnet.Tests/CommandTests/Test/CtrlCCancellationManagerTests.cs Adds unit tests for new Ctrl+C cancellation/force-exit state machine behavior.
test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs Adds integration test coverage for xUnit v3 template generation + runners across languages/frameworks.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-VisualBasic/xunit.runner.json Adds xUnit runner configuration file for v3 scenarios.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-VisualBasic/UnitTest1.vb Ensures a passing assertion is emitted for v3-generated VB tests.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-VisualBasic/Company.TestProject1.vbproj Conditional v2/v3 package/project shape including MTP runner and content file.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-VisualBasic/.template.config/template.json Adds new symbols/options + post-action and conditional sources behavior.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-VisualBasic/.template.config/localize/templatestrings.en.json Adds English localization strings for new xUnit symbols and post-action.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-VisualBasic/.template.config/ide.host.json Adds IDE symbol visibility/persistence for new template options.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-VisualBasic/.template.config/dotnetcli.host.json Wires CLI aliases for new template parameters.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-FSharp/xunit.runner.json Adds xUnit runner configuration file for v3 scenarios.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-FSharp/Company.TestProject1.fsproj Conditional v2/v3 package/project shape including MTP runner and content file.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-FSharp/.template.config/template.json Adds new symbols/options + post-action and conditional sources behavior.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-FSharp/.template.config/localize/templatestrings.en.json Adds English localization strings for new xUnit symbols and post-action.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-FSharp/.template.config/ide.host.json Adds IDE symbol visibility/persistence for new template options.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-FSharp/.template.config/dotnetcli.host.json Wires CLI aliases for new template parameters.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-CSharp/xunit.runner.json Adds xUnit runner configuration file for v3 scenarios.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-CSharp/UnitTest1.cs Ensures a passing assertion is emitted for v3-generated C# tests.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-CSharp/Company.TestProject1.csproj Conditional v2/v3 package/project shape including MTP runner and content file.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-CSharp/.template.config/template.json Adds new symbols/options + post-action and conditional sources behavior.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-CSharp/.template.config/localize/templatestrings.en.json Adds English localization strings for new xUnit symbols and post-action.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-CSharp/.template.config/ide.host.json Adds IDE symbol visibility/persistence for new template options.
template_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/XUnit-CSharp/.template.config/dotnetcli.host.json Wires CLI aliases for new template parameters.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf Adds new trans-unit for Ctrl+C force-exit hint string.
src/Cli/dotnet/Commands/Test/MTP/TestApplicationActionQueue.cs Propagates Ctrl+C cancellation token to scheduling loop and passes manager into test apps.
src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs Registers/unregisters spawned child processes so force-exit can kill the process tree.
src/Cli/dotnet/Commands/Test/MTP/Terminal/TerminalTestReporter.cs Prints “Press Ctrl+C again to force exit.” during cancellation UX.
src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs Replaces direct CancelKeyPress hook with CtrlCCancellationManager wiring.
src/Cli/dotnet/Commands/Test/MTP/ExitCode.cs Adds TestSessionAborted = 3 for force-exit behavior.
src/Cli/dotnet/Commands/Test/MTP/CtrlCCancellationManager.cs Introduces two-stage Ctrl+C state machine for cooperative cancel + forced termination.
src/Cli/dotnet/Commands/CliCommandStrings.resx Adds new user-facing localized string for force-exit Ctrl+C hint.

Copilot's findings

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

Evangelink and others added 2 commits June 8, 2026 15:45
Replace 'current' with explicit 'v3.1' in the $schema URL for the xUnit
runner config across the C#, F#, and VB templates so the schema doesn't
silently shift with future xunit.net releases.

Co-authored-by: Copilot <[email protected]>
@Evangelink
Evangelink enabled auto-merge June 8, 2026 14:27
@Evangelink

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit.v3.mtp-off" Version="3.2.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />

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.

Bumped to 3.1.5 across the C#, F#, and VB xunit v3 templates in 0a7c898.

</ItemGroup>
<!--#else-->
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />

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.

Bumped to 18.6.0 across the C#, F#, and VB xunit v3 templates in 0a7c898.

Evangelink and others added 2 commits June 9, 2026 10:21
# Conflicts:
#	test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs
…o 3.1.5 in xunit v3 templates

Applies review feedback from dotnet#54636 across the C#, F#, and VB xunit templates.

Co-authored-by: Copilot <[email protected]>
@Evangelink
Evangelink merged commit a7f7750 into dotnet:main Jun 9, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants