Using an interpolated string in a .cshtml view is giving the following intellisense error: Feature 'interpolated strings' is not used in C#5. Please use language version 6 or greater.
This and other C#7 language features are working in compiled code (.cs files).
As you can see below, the latest major version is C#7.
According to a comment in this question, "default" means "latest major version".
So why the error? Also, why doesn't it show "Latest Major Version" and "Latest Minor Version" as separate list options, as I have seen in many online examples?
UPDATE:
I finally managed to get string interpolation working in my views by installing the CodeDom providers package (The Microsoft.Net.Compilers package is related to Msbuild. The CodeDOM Providers package is related to ASP.NET and other apis that compile at runtime hence why cshtml files will show errors if this is not installed even if the latest language version is selected for msbuild). This automatically added the following to my 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>
Ref: C# 6.0 Features Not Working with Visual Studio 2015
Upgrading to MVC6 would also have fixed it I believe.
We've updated the C++ compiler and standard library in this release with enhanced support for C++11 and C++14 features.
The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion. Visual Studio for Mac doesn't support Microsoft C++, but does support . NET languages and cross-platform development.
Visual Studio 2017: mainstream support ends April 12, 2022, and the product will transition to extended support until April 2027. During extended support we'll provide fixes only for security issues. We recommend users move to the 15.9 supported baseline to remain under support.
NET5 in future versions. VS2017 does not support it.
I suspect the key to your question is when you say "in a view". Assuming this is in the context of ASP.Net, you should look at your web.config, which may specify it's own LangVersion setting (likely hardcoded to 5 in your case).
More details on configuring ASP.Net to use newer versions of C# can be found in this Roslyn documentation issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With