blog

"Error CS8107: Feature '(...)' is not available in C# 7.0. Please use language version 7.3 or greater" in Azure DevOps build

Discover effective solutions to the common issue of building projects with enum as a generic type parameter in Azure DevOps CI/CD, as shared in this insightful blog post.

Posted: 5/11/2020

During work with our latest project, where we’re using Azure DevOps for CI/CD, I encountered this error while trying to build project which used enum as generic type parameter (C# 7.3 feature). I’ve discovered that is quite common issue, without short and simple explanation, so decided to write a quick blog post on how I dealt with it.

I was really confused - build on my local machine worked fine. I was using .NET Framework 4.7 with Visual Studio 2019. I’ve looked into the documentation provided by Microsoft and found a table presented below:

Target frameworkVersionC# language version default
.NET Core3.xC# 8.0
.NET Core2.xC# 7.3
.NET Standard2.1C# 8.0
.NET Standard2.0C# 7.3
.NET Standard1.xC# 7.3
.NET FrameworkallC# 7.3

Default C# language version used by compiler - source.

It made me even more confused. According to this, my build should success - all versions of .NET Framework uses C# 7.3 by default. So why my Azure DevOps build pipeline failed?

As I found out here - Azure DevOps build .Net Core error CS8107 - explanation is simple: Azure DevOps agent uses Dotnet CLI for build process. The above table applies for the compiler that is used by Visual Studio. It looks different for Azure DevOps - Dotnet CLI in DevOps by default uses C# 7.0. This is why build succeed on my local machine, but failed in pipeline.

To force usage of C# 7.3 by Azure DevOps, you must specify this explicitly. To do this, create a file Directory.Build.props in your solution root folder and fill it in with following content:

<Project>
    <PropertyGroup>
        <LangVersion>7.3</LangVersion>
    </PropertyGroup>
</Project>

It does not affect your local build in any way - compiler for .NET Framework (and .NET Core 2.x and 3.x) by default uses C# 7.3 - it’s just the information for Azure DevOps to use proper language version.

And that’s it! After adding the file, the build pipeline finished successfully

Sources