error CS8773: "Feature 'global using directive' is not available in C# 9.0" after downgrade from net6.0 to net5.0

Viewed 20183

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.

4 Answers

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.

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

find this solution from here

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="..." />

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

<ImplicitUsings>disable</ImplicitUsings>

Related