Feature ‘using declarations’ is not available in C# 7.3. Please use language version 8.0 or greater

Issue Description

.NET build (MSBuild or Visual Studio) gives below or similar format of the error.

Feature 'using declarations' is not available in C# 7.3. Please use language version 8.0 or greater

The issue is most visible in .NET/.NET Core framework using new C# features which is not available on the target machine due to a few reasons like compilers support etc.

I found this error recently while using the new feature in the latest .NET Core 3.1 version.

Resolution: Feature ‘using declarations’ is not available

The issue can be resolved using any of the below approaches.

C# compiler determines the language version(default) based on the project’s target framework.

1. Edit Project File

Please set the language version in your project file.

Please explicitly instruct the compiler that you would like to use the specific version of the language.

If you are targetting any preview framework then the language version can be a target as a preview.

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <LangVersion>preview</LangVersion>
  </PropertyGroup>
</Project>

One can also Target specific version Example: ‘8.0’ as shown below,

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <LangVersion>8.0</LangVersion>
  </PropertyGroup>
</Project>

2. Configuring for Multiple projects

You can target multiple projects to use the specific or preview or latest version of the C# language version using Directory.Build.props file.

Please update the file as below with the source repository.

Directory.Build.props file

3. Settings on Build Server

If using a build server to build the project using MSBuild command as below,

msbuild /property:langversion=latest

blank

If the above settings doesn’t work, please mention the version as below,

msbuild /property:langversion=8.0

Note: For local Visual Studio IDE settings, please reload the project to make settings effective.

Guidelines

As per Microsoft.

Moving forward, however, each version of each framework will have a single supported and default version, and we won’t support arbitrary versions. To reflect this change in support, this commit permanently disables the language version combo box and adds a link to a document explaining the change.

I have discussed the same in the below article already,

Please note that the target project when built gets the highest compatible language version by default as per this versioning semantics

If using .NET or .NET Core then this framework will always target only a single framework and which will also be a default version.

This versioning could vary from machine to machine depending on the target framework version installed.

Feature'using declarations' is not available

As a good practice, one can always use the latest version in their project.

Example

<LangVersion>latest</LangVersion>

References :

https://github.com/dotnet/project-system/pull/4923/commits/fc1f7f691851670909ed38fdfc3b4a4ac79c5e4b

Summary

In this post, we saw how to target the latest version of C# when building a .NET Core application and resolve common issues related to a specific version.

That’s all! Happy coding!

Does this help you fix your issue?

Do you have any better solutions or suggestions? Please sound off your comments below.



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



3 thoughts on “Resolved: Feature ‘using declarations’ is not available in C#

  1. I’m still getting error “Feature ‘recursive patterns’ is not available in C# 7.3. Please use language version 8.0 or greater.”

    1. Hello Gordey, Thanks for your query. Please make sure you have either .NET Core 3.0 or .NET Standards 2.1 is installed on the target machine.

Leave a Reply

Your email address will not be published. Required fields are marked *