Repository navigation
Add XUnitVersion v3 option (MTP default) to xunit templates - #54636
Merged
Evangelink merged 6 commits intoJun 9, 2026
Merged
Conversation
) 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
force-pushed
the
dev/amauryleve/xunit-template-v3-option
branch
from
June 8, 2026 12:51
f494bf3 to
da3b3e5
Compare
Contributor
There was a problem hiding this comment.
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 andxunit.runner.json. - Add template integration coverage for xUnit v3 across languages and runner options.
- Add Ctrl+C cancellation manager for MTP
dotnet testorchestration (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
Youssef1313
reviewed
Jun 8, 2026
Youssef1313
reviewed
Jun 8, 2026
Youssef1313
reviewed
Jun 8, 2026
Youssef1313
reviewed
Jun 8, 2026
Evangelink
commented
Jun 8, 2026
Evangelink
commented
Jun 8, 2026
Evangelink
commented
Jun 8, 2026
Co-authored-by: Amaury Levé <[email protected]>
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]>
YuliiaKovalova
approved these changes
Jun 8, 2026
Evangelink
commented
Jun 8, 2026
Evangelink
commented
Jun 8, 2026
Evangelink
commented
Jun 8, 2026
Co-authored-by: Amaury Levé <[email protected]>
Evangelink
enabled auto-merge
June 8, 2026 14:27
Member
Author
|
@copilot resolve the merge conflicts in this pull request |
Youssef1313
reviewed
Jun 8, 2026
| <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" /> |
Member
There was a problem hiding this comment.
Suggested change
| <PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" /> | |
| <PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" /> |
Member
Author
There was a problem hiding this comment.
Bumped to 3.1.5 across the C#, F#, and VB xunit v3 templates in 0a7c898.
Youssef1313
reviewed
Jun 8, 2026
| </ItemGroup> | ||
| <!--#else--> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" /> |
Member
There was a problem hiding this comment.
Suggested change
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" /> | |
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" /> |
Member
Author
There was a problem hiding this comment.
Bumped to 18.6.0 across the C#, F#, and VB xunit v3 templates in 0a7c898.
# 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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Partial fix for #54499.
Adds an opt-in xUnit v3 path to the built-in
xunittemplates (C#/F#/VB) while keeping xUnit v2 as the default (no change for existing users).What this adds
--xunit-versionchoice option ondotnet new xunitwith valuesv2(default) andv3.--test-runnerchoice option, only meaningful when--xunit-version v3is used. Defaults toMicrosoft.Testing.Platform;VSTestis the alternative.Behavior
dotnet new xunitMicrosoft.NET.Test.Sdk+xunit.runner.visualstudio+coverlet.collector.dotnet new xunit --xunit-version v3OutputType=Exe,UseMicrosoftTestingPlatformRunner=true, referencesxunit.v3.mtp-v2, includes axunit.runner.jsonfile, and a post-action creates/updatesglobal.jsonwith the runner property. Shape mirrors the official xunit.net v3 template.dotnet new xunit --xunit-version v3 --test-runner VSTestMicrosoft.NET.Test.Sdk+xunit.v3.mtp-off+xunit.runner.visualstudio+xunit.runner.json.Files changed
For each of the C#, F#, and VB
xunittemplates undertemplate_feed/Microsoft.DotNet.Common.ProjectTemplates.11.0/content/:.template.config/template.json— addedXUnitVersionandTestRunnerchoice symbols,sourcesmodifier to excludexunit.runner.jsonoutside v3, and anaddJsonPropertypost-action gated on v3+MTP.Assert.True(true)body when v3 (so the generated project has at least one passing test)..template.config/dotnetcli.host.json—--xunit-versionand--test-runnerCLI 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).xunit.runner.jsonper language template.Tests:
test/dotnet-new.IntegrationTests/DotnetNewTestTemplatesTests.cs— addedXUnitV3ProjectTemplate_WithTestRunner_CanBeInstalledAndTestsArePassingtheory covering 3 languages × 2 runners.Validation
ProjectTemplate_CanBeInstalledAndTestsArePassingforxunit(default v2): 3/3 passing — no regression.Out of scope (intentionally)
templatestrings.*.jsonfiles are not updated by hand — same pattern used for the recent MSTestTestRunnersymbol; OneLocBuild fills them in.