【发布时间】:2022-01-21 11:45:57
【问题描述】:
在 Visual Studio 2022 中使用 EF Core 和 Npgsql 创建 ASP.NET Core 6 MVC 应用程序。
点击“清除所有 NuGet 缓存”按钮后
Visual Studio > Tools Options > NuGet Package Manager > General
源代码中的属性 Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp9
CSharpParseOptions.Default.WithLanguageVersion(Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp9);
抛出编译错误
错误 CS0117 'LanguageVersion' 不包含 'CSharp9'
所有 NuGet 包都是最新的。如何解决这个问题?程序集信息不包含 CSharp9 成员:
#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
}
}
Microsoft.CodeAnalysis.CSharp.dll 文件没有被任何 anyprojet 直接引用。
NuGet 窗口不显示任何名称中包含 roslyn 的包。
【问题讨论】:
-
您的项目使用哪种语言版本?
-
你试过重启VS吗?如果您的项目支持它,请先尝试从命令行构建(使用您用于命令行构建的任何内容)
-
看起来 Ef Core Npgsql 提供程序需要 9,因为使用 8 脚手架会引发错误
CS8400: Feature 'or pattern' is not available in C# 8.0. Please use language version 9.0 or greater.重新启动 Visual Studio 后,选择干净的项目并重建所有问题仍然存在。如何从命令行构建它? -
那么做两件事:确保在您的项目中也使用语言版本 9(或更高版本)。 (在项目文件中设置
<LangVersion>9</LangVersion>)。大多数(较大的)项目都准备好使用一些特殊的构建工具(例如 Nuke)从命令行构建。如果您不知道那是什么,您可以尝试标准的 .NET 构建命令:dotnet build <YourSolution>。 -
从命令行构建解决方案后问题仍然存在。看起来这个 dll 文件在解决方案中有两个版本。我更新了问题。如何删除旧版本?
标签: c# visual-studio npgsql roslyn-code-analysis csharpcodeprovider