在.cshtml视图中使用插值字符串会导致以下intellisense错误:Feature 'interpolated strings' is not used in C#5. Please use language version 6 or greater.
此和其他C#7语言功能在编译代码(.cs文件)中工作, 。VS2017 - C#7语言功能在MVC视图中不起作用
正如您在下面看到的,最新的主要版本是 C#7。
根据this question评论,“默认” 的意思是 “最新的主要版本”。
那么为什么错误呢?另外,为什么它没有显示“最新主要版本”和“最新次要版本”作为单独的列表选项,正如我在许多在线示例中看到的那样?
更新:
我终于设法通过安装CodeDom providers package(该Microsoft.Net.Compilers包拿到串插在我的意见的工作是有关的MSBuild CodeDOM的供应商包与ASP.NET和其他apis在运行时编译,因此即使为msbuild选择了最新的语言版本,为什么cshtml文件也会显示错误(如果未安装该文件)。这种自动添加以下到我的web.config:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
编号:C# 6.0 Features Not Working with Visual Studio 2015
升级到MVC6也有固定的,我相信。
您正在使用哪个版本的VS2017?你的截图看起来让人联想到RC版本;不是发布的版本。 –
@DavidArno - Enterprise。 – Kev
对不起,我的意思是如15.3.5中的版本。你可以通过'帮助 - >关于Microsoft Visual Studio'来找到答案。 –