If you have created a Console Application Project, an ASP.NET Core Web App/Web API project, or a Worker Service Project using Visual Studio 2022 latest preview (17.0.0 Preview 3.1) targetting the latest .NET 6 Preview (.NET 6 Preview 7), you will see a significant change to the template code/boilerplate code that is generated.
All of them now uses Top-Level statements and most importantly you won't see all the usings that were previously there.
Console Application
Console Application Project (Microsoft.NET.Sdk) |
ASP.NET Core Web API
ASP.NET Core Web API Project (Microsoft.NET.Sdk.Web) |
Worker Service
Worker Service Project (Microsoft.NET.Sdk.Worker) |
This is all made possible via Global Usings that got introduced as part of C# 10. The .NET SDK now implicitly includes a set of default namespaces for C# projects which targets .NET 6 or later and use one of the following SDKs:
- Microsoft.NET.Sdk
- Microsoft.NET.Sdk.Web
- Microsoft.NET.Sdk.Worker
// <autogenerated />
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
// <autogenerated />
// Microsoft.NET.Sdk related global usings plus the following
global using global::System.Net.Http.Json;
global using global::Microsoft.AspNetCore.Builder;
global using global::Microsoft.AspNetCore.Hosting;
global using global::Microsoft.AspNetCore.Http;
global using global::Microsoft.AspNetCore.Routing;
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging;
// <autogenerated />
// Microsoft.NET.Sdk related global usings plus the following
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging;
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
<!--Disable implicit namespaces in Microsoft.NET.Sdk-->
<DisableImplicitNamespaceImports_DotNet>true</DisableImplicitNamespaceImports_DotNet>
<!--Disable implicit namespaces in Microsoft.NET.Sdk.Web-->
<DisableImplicitNamespaceImports_Web>true</DisableImplicitNamespaceImports_Web>
<!--Disable implicit namespaces in Microsoft.NET.Sdk.Worker-->
<DisableImplicitNamespaceImports_Worker>true</DisableImplicitNamespaceImports_Worker>
<ItemGroup>
<Import Remove="System.Net.Http" />
<Import Include="System.Text.Json" />
</ItemGroup>
// <autogenerated />
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using global::System.Text.Json;
Jaliya
No comments:
Post a Comment