Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Devops Pipeline getting `default literal` error on Pipeline build

I have a standard pipeline agent that works for CI whenever a pull request merged into master. It was working fine until I merged a pull request created by a visual-studio-2019 developed branch. Now I am getting

error CS8107: Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater.

It is working fine when I push any changes with vs2017.

What should I do to avoid this error?

P.S: I want to keep using vs2019

Thanks in advance.

like image 759
ilkerkaran Avatar asked Apr 19 '19 08:04

ilkerkaran


Video Answer


2 Answers

This happen when you have code like the following:

MyType foo = default; // assign the default value for this type

In C# 7, the supported syntax is:

MyType foo = default(MyType);

but the simpler form was added in 7.1.

There are two ways to fix this:

  1. Don't use the newer form. Change any existing instances of default to have a type, and change the settings so that the IDE will prefer the verbose form. Here's a picture with the new form turned on, just change the Yes to a No: Tools->Options setting for 'default' expression If you're using .editorconfig files, you can configure the csharp_prefer_simple_default_expression setting.
  2. Set the language version for your project to be high enough to support the new syntax. Keep in mind that if you set it to latest it may use a different version between your development box (VS2019) and your build agent (e.g. possibly still on VS2017).
like image 145
Jimmy Avatar answered Oct 24 '22 12:10

Jimmy


I just solved this issue by updating my Agent Pool in the build pipeline to use "Hosted Windows 2019 with VS2019"

enter image description here

like image 27
Hard Tour Vela Avatar answered Oct 24 '22 12:10

Hard Tour Vela