Reputation: 2728
There is a similar question to this here but I believe that involves a different cause.
I moved a class from a newer project into an older project. Both were targeting .net 4.6 however after the move I received the following error on build.
Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater.
I tried setting my project to build with C# 6 in the properties window with no change.
Upvotes: 33
Views: 29787
Reputation: 2966
The GUI would not let me change the version, but I could change manually in the csproj-file.
<LangVersion>5</LangVersion>
to
<LangVersion>6</LangVersion>
Upvotes: 0
Reputation: 1108
(It can applicable VS 2019 - .NET Framework 4.8 Web Application projects easily)
I have realized this issue after install DotNetCompilerPlatform v3.6
I have looked for TheColonel26's answer but I couldn't change selected language version:
Appearantly, we can not change selected language version. (For details look here)
After that I have used kfwbird's answer but with changes for newer version:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
Now it works as should be.
Upvotes: 8
Reputation: 83
Add this to your web.config. It is probably added automatically after installing DotNetCompilerPlatform.
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
Upvotes: 5
Reputation: 2728
I eventually found the place to change it. It seems sometimes when you update your targets framework version this does not get changed.
Upvotes: 24