在.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'來找到答案。 –