LanguageVersion does not contain a definition for C# 9 after clearing NuGet caches
Creating ASP.NET Core 6 MVC application with EF Core and Npgsql in Visual Studio 2022.
After clicking "Clear All NuGet Cache(s)" button in
Visual Studio > Tools Options > NuGet Package Manager > General
property Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp9 in source code
CSharpParseOptions.Default.WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp9);
throws compile error
Error CS0117 'LanguageVersion' does not contain a definition for
'CSharp9'
All NuGet packages are up to date. Re-starting Visual Studio, selection clean project and re-build solution does not fix this.
It looks like Ef Core Npgsql provider requires 9 since using 8 scaffold throws error CS8400: Feature 'or pattern' is not available in C# 8.0. Please use language version 9.0 or greater.
How to fix this ? Assembly information does not contain CSharp9 member :
#region Assembly Microsoft.CodeAnalysis.CSharp, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// location unknown
// Decompiled with ICSharpCode.Decompiler 6.1.0.5902
#endregion
namespace Microsoft.CodeAnalysis.CSharp
{
//
// Summary:
// Specifies the language version.
public enum LanguageVersion
{
//
// Summary:
// C# language version 1
CSharp1 = 1,
//
// Summary:
// C# language version 2
CSharp2 = 2,
//
// Summary:
// C# language version 3
//
// Remarks:
// Features: LINQ.
CSharp3 = 3,
//
// Summary:
// C# language version 4
//
// Remarks:
// Features: dynamic.
CSharp4 = 4,
//
// Summary:
// C# language version 5
//
// Remarks:
// Features: async, caller info attributes.
CSharp5 = 5,
//
// Summary:
// C# language version 6
//
// Remarks:
// Features:
// • Using of a static class
// • Exception filters
// • Await in catch/finally blocks
// • Auto-property initializers
// • Expression-bodied methods and properties
// • Null-propagating operator ?.
// • String interpolation
// • nameof operator
// • Dictionary initializer
CSharp6 = 6,
//
// Summary:
// C# language version 7.0
//
// Remarks:
// Features:
// • Out variables
// • Pattern-matching
// • Tuples
// • Deconstruction
// • Discards
// • Local functions
// • Digit separators
// • Ref returns and locals
// • Generalized async return types
// • More expression-bodied members
// • Throw expressions
CSharp7 = 7,
//
// Summary:
// C# language version 7.1
//
// Remarks:
// Features:
// • Async Main
// • Default literal
// • Inferred tuple element names
// • Pattern-matching with generics
CSharp7_1 = 701,
//
// Summary:
// C# language version 7.2
//
// Remarks:
// Features:
// • Ref readonly
// • Ref and readonly structs
// • Ref extensions
// • Conditional ref operator
// • Private protected
// • Digit separators after base specifier
// • Non-trailing named arguments
CSharp7_2 = 702,
//
// Summary:
// C# language version 7.3
CSharp7_3 = 703,
//
// Summary:
// C# language version 8.0
CSharp8 = 800,
//
// Summary:
// The latest major supported version.
LatestMajor = 2147483645,
//
// Summary:
// Preview of the next language version.
Preview = 2147483646,
//
// Summary:
// The latest supported version of the language.
Latest = int.MaxValue,
//
// Summary:
// The default language version, which is the latest supported version.
Default = 0
}
}