90

I have a project that was initially created for .NET 6 but then I needed to downgrade it to .NET 5. I changed Target framework in Project Properties and tried to compile. As a result I received a bunch of the errors:

GlobalUsings.g.cs(2,1,2,29): error CS8773: Feature 'global using directive' is not available in C# 9.0. Please use language version 10.0 or greater.

File GlobalUsings.g.cs is created automatically and it reappears every time after compilation.

Yuriy Gavrishov
  • 4,341
  • 2
  • 17
  • 29

5 Answers5

212

Finally I found that the reason is an extra property ImplicitUsings in the project file that is not supported by .net 5.0.

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

I needed to remove ImplicitUsings from the file.

Yuriy Gavrishov
  • 4,341
  • 2
  • 17
  • 29
19

remove <ImplicitUsings>enable</ImplicitUsings> in the csproj project file, then can build success

find this solution from here

lily
  • 191
  • 1
  • 2
11

Remove the tag indeed work.
But just change the value of it did the trick as well!

<ImplicitUsings>disable</ImplicitUsings>

Thiago Timm
  • 181
  • 2
  • 4
7

To get rid of this error which is caused by downgrading below net6.0.

Remove the following items from the .csproj file:

  1. <ImplicitUsings>
  2. <Using Include="..." />
Mehrdad
  • 1,523
  • 9
  • 23
0

If you don't want to remove the ImplicitUsings or made changes to the project file. You can tell the build cli to disable it during build process by

dotnet build --configuration "Release" --framework "net5.0" /p:ImplicitUsings=false /p:PublishReadyToRun=false
Supawat Pusavanno
  • 2,968
  • 28
  • 21