.NET Framework项目中的可空引用类型不能与IntelliSense一起使用

Rud*_*dey 5 intellisense visual-studio c#-8.0 nullable-reference-types .net-4.8

当我创建一个新的控制台应用程序(.NET Framework 4.8)并尝试使用C#8的可为空的引用类型时,我看到以下内容:

可为空的引用类型的注释只能在“ #nullable”注释上下文中的代码中使用

而且,我在构建输出中得到以下警告:

warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
Run Code Online (Sandbox Code Playgroud)

可以理解,我尚未启用可为空的引用类型。我将以下内容添加到我的.csproj中:

warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
Run Code Online (Sandbox Code Playgroud)

这使构建警告消失,但是Visual Studio的IntelliSense一直在抱怨

如何配置Visual Studio,使其理解我在.NET Framework项目中使用可为空的引用类型,而无需#nullable在所有地方使用?


相反,如果我创建一个新的.NET Core 3.0控制台应用程序,那么一切都会按预期进行。

Lan*_*SFT 5

如何配置 Visual Studio,使其了解我在 .NET Framework 项目中使用可为 null 的引用类型,而不在各处使用 #nullable?

恐怕答案是否定的,因为这可能是一个关于 的问题VS Intellisense

我发现 msbuild(VS 构建系统)可以在构建过程中很好地识别项目C#8.0中的内容。.net framework4.8但 Intellisense(VS 的一项功能)不能,所以我报告了它。如果有人对此问题感兴趣,有关该问题的更多详细信息请参阅Intellisense can't recognize C#8.0 in project that Targets .net Framework 4.8

行为是在项目中Intellisense没有为我们显示正确的消息。这是一个只能通过修复来解决的问题。因此,除非我们在报告此问题后进行修复,否则没有有效的方法来解决 Intellisense(VS 功能)的此问题。我们可以,但这是一个坏主意...net framework 4.8C#8.0Suppress or Configure CS8632's severity

  • 遗憾的是微软似乎对此无所作为。 (2认同)