Rider 建议使用 C# 8 语法,但未能构建解决方案

Posted

技术标签:

【中文标题】Rider 建议使用 C# 8 语法,但未能构建解决方案【英文标题】:Rider suggests to use C# 8 syntax but then fails to build solution 【发布时间】:2019-09-08 07:23:01 【问题描述】:

Rider 建议使用 C# 8 语法,例如 using declaration 或 async streams。

但是,当我应用推荐的重构时,构建会因语法错误而失败。

我的csproj.DotSettings 文件包含设置为latest 的语言级别:

<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">latest</s:String>
...
</wpf:ResourceDictionary>

澄清一下 - 我完全赞成使用 C# 8。我在哪里可以设置编译器目标语言?还是只是还不支持?

在我的项目属性中:

【问题讨论】:

【参考方案1】:

要使用 C# 8,您需要安装 MSBuild 16,然后在项目设置 (csproj) 中编写语言的确切版本。

</PropertyGroup>
  ...
  <LangVersion>8</LangVersion>
</PropertyGroup>

【讨论】:

以上是关于Rider 建议使用 C# 8 语法,但未能构建解决方案的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Rider 中触发文件更改的设计时构建?

Rider 可以编译啥语言

如何在 Rider for Mac 版本中允许“不安全代码”?

Rider 2018.1 iOS 模拟器在构建后未运行

如何在 JetBrains Rider 中添加 C# 解决方案文件?

如何在 JetBrains Rider 中添加/使用 C# 库?