Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# 10: Disable Global Using

Tags:

c#

.net

c#-10.0

How can I disable the new default global usings in C# 10 (see here: https://github.com/dotnet/aspnetcore/issues/32451)?

I want to see the used namespaces at a glance and don't want to look up the documentation which namespaces are used globally.

like image 866
Martinaut Avatar asked Aug 14 '21 10:08

Martinaut


Video Answer


2 Answers

<ImplicitUsings>disable</ImplicitUsings> has to be added to the PropertyGroup in the csproj-file.

For example:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>disable</ImplicitUsings>
    </PropertyGroup>
</Project>

If you are using a beta version of .NET 6, you will have to use <DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>.

like image 50
Martinaut Avatar answered Oct 28 '22 05:10

Martinaut


In my case I had to remove

<ImplicitUsings>enable</ImplicitUsings>

from csproj

like image 10
Luca Trazzi Avatar answered Oct 28 '22 04:10

Luca Trazzi