-
Notifications
You must be signed in to change notification settings - Fork 0
Description
C# 10 introduced support for Implicit Global Usings, which automatically add common namespaces based on the target SDK in the csproj file. This can reduce the number of using statements needed on each class.
Enabling
Implicit global usings can be enabled in the csproj file by setting the following property:
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>Limitations
While this is advertised as a C# 10 feature, it's actually dependent on the .NET 6 SDK, due to tooling integrated with dotnet (and, under the hood, msbuild). Since we have no intention of upgrading the OnTopic library to .NET 6 anytime soon (in order to maintain backward compatibility) this could be a problem. That said, so long as the latest version of the .NET SDK is used to compile the project, this may still be supported. TBD.
Implicit Using Directives
With the Microsoft.NET.Sdk, we get the following implicit usings:
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Net.Http;
global using System.Threading;
global using System.Threading.Tasks;With the Microsoft.NET.Sdk.Web, we additionally get:
global using System.Net.Http.Json
global using Microsoft.AspNetCore.Builder
global using Microsoft.AspNetCore.Hosting
global using Microsoft.AspNetCore.Http
global using Microsoft.AspNetCore.Routing
global using Microsoft.Extensions.Configuration
global using Microsoft.Extensions.DependencyInjection
global using Microsoft.Extensions.Hosting
global using Microsoft.Extensions.Logging