Azure Devops Pipeline getting `default literal` error on Pipeline build
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:
- 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: If you're using .editorconfig files, you can configure thecsharp_prefer_simple_default_expression
setting. - 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).
I just solved this issue by updating my Agent Pool in the build pipeline to use "Hosted Windows 2019 with VS2019"