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.
In computer programming, string interpolation (or variable interpolation, variable substitution, or variable expansion) is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values.
The string interpolation result is 'Hello, World!' . You can put any expression inside the placeholder: either an operator, a function call, or even more complex expressions. ${n1 + n2} is a placeholder consisting of the addition operator and 2 operands.
The string interpolation feature is built on top of the composite formatting feature and provides a more readable and convenient syntax to include formatted expression results in a result string.
It is also known as variable substitution, variable interpolation, or variable expansion. It is a process of evaluating string literals containing one or more placeholders that get replaced by corresponding values.
Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater 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.
asp.net mvc 5 - Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater. - Stack Overflow Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater. The following line does not compile when I put in a Razor View.
Feature 'interpolated strings' is not available in C# 4. Please use language version 6 or greater. - General and Gameplay Programming - GameDev.net Chat in the GameDev.net Discord! Feature 'interpolated strings' is not available in C# 4.
This feature is available starting with C# 6. String interpolation provides a more readable and convenient syntax to create formatted strings than a string composite formatting feature. The following example uses both features to produce the same output:
I eventually found the place to change it. It seems sometimes when you update your targets framework version this does not get changed.
Install DotNetCompilerPlatform version 2.1.0
(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.
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>
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