-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EPIC] .NET 6 C# project templates use latest language idioms #3359
Comments
To enable nullability checking in ASP.NET Core & Blazor there are a number of issues tracking related work:
Of particular concern is the impact of nullability checking on scaffolding and Razor. |
@danroth27 anywhere we emit code into a project is indeed going to be problematic if it isn't taking nullability into account. The nullability in the framework APIs itself shouldn't cause issues AFAICT though right? With that in mind, we'll likely need to include updating scaffolding content within the scope of this effort, to ensure the code emitted appropriately handles nullables. |
Regarding using top-level statements by default. My concern is that local methods don't support overloading and they look like regular methods when using top-level statements, which might confute people: dotnet/csharplang#3112 (comment) Also with top-level statements you cannot use something like System.CommandLine.DragonFruit, but that's less of an issue then the first one. |
I know you are probably working already on tough timelines, but is this dotnet/templates#520 something worth considering. I added that issue after the community call asking for feedback and probably mixed up the template and templating repo ;). |
These template changes do need opt-out options that don't involve "copy the old template and start from there" as the docs at https://aka.ms/new-console-template suggest. I'll start with the disclaimer that I sadly cannot perform a full evaluation of these changes as my VS2022 installation appears to be broken (projects won't load at all within solutions, so other than the default Program.cs, Class1.cs or manually selected files opening without language features, I can't see how it all works in practice), but I do have strong feelings towards these changes. I'm all in for new features such as There's also the matter of code style consistency and preferences, as for consistency l fear this would be conflicting with existing projects and solutions that are upgraded to .NET 6 and new classes/projects are added (sadly I cannot test this at the moment), as for preferences, I (and others may) prefer explicit type definitions over |
Putting a global using for Little paper cuts like that (I have to know how to add a special property to a CSPROJ) are the kinds of things that could really erode the value in projects like Serilog over time. Any discussion open on this where I can catch up on the thinking so far? |
@nblumhardt that's worth creating a specific issue to allow relevant discussion. Create one in the dotnet/sdk repo and tag me and we can chat about some potential mitigations. |
Closing this as work in .NET 6 has been completed. A couple of items were pushed to post-6.0. |
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:
new
expressionsIssues
Area owners
Implementation Considerations
--langVersion
option and will need to condition the relevant changes based on the supplied value so that only compatible features are utilized in the new projectTop-level statements
Program.cs
will be updated to use top-level statementsGlobal using directives
global using
statements should appear in the templateusing
statements in project templates that conflict with new SDK-driven default global using directives will be removedFile-scoped namespaces
main
builds but is expected to land during preview.7Target-typed
new
expressionsprivate 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 repeatedNullable reference types
<Nullable>enable</Nullable>
added to their.csproj
files.cs
,.cshtml
, and.razor
files in existing project templates will be updated to appropriately handle nullable reference typesasync Main
Program.cs
containing astatic void Main
method declaration with a body that includes calls toTask
-returning methods (or methods with aTask
-returning alternative) will be updated to declare the method asasync
and the calls toTask
-returning methods will be updated with theawait
keyword.The text was updated successfully, but these errors were encountered: