-
Notifications
You must be signed in to change notification settings - Fork 393
Closed
Labels
EpicGroups multiple user stories. Can be grouped under a theme.Groups multiple user stories. Can be grouped under a theme.area: template-contentThe issue is related to content of template packages managed in this repo (/template_feed)The issue is related to content of template packages managed in this repo (/template_feed)
Milestone
Description
In .NET 6, the included C# project templates will use the latest language idioms.
The following language features will be used or enabled by default in the SDK-included project templates as applicable:
- Top-level statements
- Global using directives (via SDK driven defaults)
- File-scoped namespaces (compiler tracking issue)
- Target-typed
newexpressions - Nullable reference types
- async Main
Issues
- Console/Class lib project templates use latest C# language idioms #3360
- Test project templates use latest C# language idioms test-templates#164
- ASP.NET Core project templates use latest C# language idioms aspnetcore#33947
- Blazor project templates use latest C# language idioms aspnetcore#33948
- WinForms project templates use latest C# language idioms winforms#5171
- Import Windows Forms related props and targets into Windows Desktop wpf#4779
- WPF project templates use latest C# language idioms wpf#4774
- MAUI project templates use latest C# language idioms maui#1497
- Android project templates use latest C# language idioms android#6076
- iOS/Mac project templates use latest C# language idioms macios#12085
- Update scaffolders to support nullable reference types Scaffolding#1594
- Support file-scoped namespace declarations in generated .cs files efcore#25223
Area owners
| Template area | Owner |
|---|---|
| Neutral (Console/Class lib) | @KathleenDollard |
| Unit testing | @kendrahavens |
| ASP.NET Core/gRPC/Worker | @DamianEdwards |
| Blazor | @danroth27 |
| WinForms | @OliaG |
| WPF | @OliaG |
| MAUI | @mhutch |
Implementation Considerations
- All changes detailed here will only be applied when the project is created targeting .NET 6+ (the default)
- Some templates have a
--langVersionoption and will need to condition the relevant changes based on the supplied value so that only compatible features are utilized in the new project - Making the changes opt-in is not being considered at this time as it defeats the intended purpose which is to have the default experience for new projects reflect the latest language idioms
- ❓ Should all changes detailed here have corresponding template options to allow opting-out of them at project creation time?
- ☑️ Decision on this is "No" for now. We can revisit based on feedback if necessary.
Top-level statements
- Language feature documentation
- Introduced in C# 9
- Project templates with an existing
Program.cswill be updated to use top-level statements
Global using directives
- Language feature implementation issue
- Introduced in C# 10
- This feature is driven by SDK changes and as such no actual
global usingstatements should appear in the template - Existing
usingstatements in project templates that conflict with new SDK-driven default global using directives will be removed - The following namespaces are being globally included by the SDKs:
- Microsoft.NET.SDK:
- System
- System.Collections.Generic
- System.IO
- System.Linq
- System.Net.Http
- System.Threading
- System.Threading.Tasks
- Microsoft.NET.SDK.Web:
- Everything included by Microsoft.NET.SDK, plus:
- System.Net.Http.Json
- Microsoft.AspNetCore.Builder
- Microsoft.AspNetCore.Hosting
- Microsoft.AspNetCore.Http
- Microsoft.AspNetCore.Routing
- Microsoft.Extensions.Configuration
- Microsoft.Extensions.DependencyInjection
- Microsoft.Extensions.Hosting
- Microsoft.Extensions.Logging
- Microsoft.NET.SDK.Worker
- Everything included by Microsoft.NET.SDK, plus:
- Microsoft.Extensions.Configuration
- Microsoft.Extensions.DependencyInjection
- Microsoft.Extensions.Hosting
- Microsoft.Extensions.Logging
- Microsoft.NET.SDK:
File-scoped namespaces
- Language feature implementation issue
- Introduced in C# 10
- Any namespaces declared in existing project templates will be changed to use the file-scoped namespaces syntax
- ℹ️ This feature is not yet available in
mainbuilds but is expected to land during preview.7
Target-typed new expressions
- Language feature documentation
- Introduced in C# 9
- Any constructor invocation where the type name can be omitted to reduce its duplication
- ✔️
private readonly static object s_syncObj = new object();toprivate readonly static object s_syncObj = new(); - ❌
var someStrings = new List<string>();stays as it is now as the type name is not repeated
- ✔️
Nullable reference types
- Language feature documentation
- Introduced in C# 8
- Existing project templates will enable the feature by default by having
<Nullable>enable</Nullable>added to their.csprojfiles- ℹ️ Enabling nullable reference types via SDK defaults was considered but rejected due to concerns with the experience during migration of existing projects to .NET 6, in that existing projects changed to target the .NET 6 TFM as part of migration will immediately exhibit compiler warnings associated with the feature being enabled and not handled correctly by the existing project code
.cs,.cshtml, and.razorfiles in existing project templates will be updated to appropriately handle nullable reference types- Code generation tools (e.g. Scaffolding, EF Core Migrations, etc.) should also be updated to ensure they produce code that is aligned with the nullable configuration of the target project.
async Main
- Language feature documentation
- Introduced in C# 7.1
- Project templates with an existing
Program.cscontaining astatic void Mainmethod declaration with a body that includes calls toTask-returning methods (or methods with aTask-returning alternative) will be updated to declare the method asasyncand the calls toTask-returning methods will be updated with theawaitkeyword.
rkttu, WeihanLi, lori2326 and fahadashiq12bravecobra, lavilaso, Igorgro and TanvirArjelhalter73, vijayrkn, saint4eva, bradygaster, MadsTorgersen and 9 moreamantinband
Metadata
Metadata
Assignees
Labels
EpicGroups multiple user stories. Can be grouped under a theme.Groups multiple user stories. Can be grouped under a theme.area: template-contentThe issue is related to content of template packages managed in this repo (/template_feed)The issue is related to content of template packages managed in this repo (/template_feed)