Repository navigation
Make ImplicitUsings/Nullable conditional on TFM in test templates - #54594
Merged
Merged
Conversation
Fixes #51969. Test templates previously emitted `<LangVersion>latest</LangVersion>`, `<ImplicitUsings>enable</ImplicitUsings>` and `<Nullable>enable</Nullable>` unconditionally, even for .NET Framework target frameworks (e.g. net472) where these settings are not officially supported and can produce build errors. Follow the pattern used by ClassLibrary-CSharp/ConsoleApplication-CSharp: * langVersion symbol defaults to """" (no LangVersion property emitted unless user explicitly passes --langVersion). * csharp*/csharpFeature_* computed symbols gate ImplicitUsings, Nullable and `<Using>` items so they only appear when the target language version actually supports them. * Source files (Test1.cs/UnitTest1.cs/MSTestSettings.cs) use template-engine `#if` blocks to choose between file-scoped namespaces (modern) and traditional namespaces with explicit `using` directives (pre-C# 10). * MSTest VB/F# templates previously had unconditional C#-only properties (ImplicitUsings/Nullable/`<Using>`); remove them for consistency with NUnit-VB/F# and XUnit-VB/F# templates. Tested manually: mstest, mstest-playwright, nunit, xunit, nunit-playwright all generate and build successfully for both net11.0 and net472 (where applicable). Co-authored-by: Copilot <[email protected]>
Copilot stopped reviewing on behalf of
Evangelink due to an error
June 4, 2026 18:32
Evangelink
enabled auto-merge
June 5, 2026 07:23
JanKrivanek
approved these changes
Jun 5, 2026
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s), but failed to run 1 pipeline(s). |
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.
Fixes #51969.
Test templates previously emitted
<LangVersion>latest</LangVersion>,<ImplicitUsings>enable</ImplicitUsings>and<Nullable>enable</Nullable>unconditionally, even for .NET Framework target frameworks (e.g.net472) where these settings are not officially supported and can produce build errors (e.g. CS8370 about global usings requiring C# 10).This change follows the pattern already used by
ClassLibrary-CSharp/ConsoleApplication-CSharp:C# test templates (MSTest, Playwright-MSTest, NUnit, XUnit, Playwright-NUnit)
langVersionsymbol now defaults to""so no<LangVersion>property is emitted unless the user explicitly passes--langVersion.csharp*/csharpFeature_*computed symbols gate<ImplicitUsings>,<Nullable>and the<Using>items so they only appear when the target language version supports them.mstest,mstest-playwright), anetFrameworkregex symbol (^net4\d) is added and combined with the language gate.Test1.cs/UnitTest1.cs/MSTestSettings.cs) use template-engine#ifblocks to switch between:namespace { ... }blocks with explicitusingdirectives (pre-C# 10 / netFramework).MSTest VB / F# templates
Removed unconditional C#-only properties (
<ImplicitUsings>,<Nullable>,<Using>items). These had no effect on the VB/F# compilers and are inconsistent with the existing NUnit-VB/F# and XUnit-VB/F# templates which don't emit them.VB / F#
langVersionChanged default from
"latest"to""forMSTest-VisualBasic,NUnit-VisualBasic,MSTest-FSharp,NUnit-FSharp.Localization
The auto-generated
templatestrings.*.jsonfiles underXUnit-CSharp/.template.config/localize/were updated by the templates build target to include the newlangVersionsymbol description (English strings as placeholders — will be properly localized via the standard loc flow).Verification
Templates package builds clean (0 errors / 0 warnings).
Manually generated and built all 15 applicable combinations:
For
net472, generated csproj has none of<LangVersion>/<ImplicitUsings>/<Nullable>/<Using>items, and the source files use traditional namespaces with explicitusingdirectives.For
net11.0, the modern user experience is preserved (<ImplicitUsings>enable</ImplicitUsings>,<Nullable>enable</Nullable>, file-scoped namespaces, no explicit usings).