'Using C# 6 with WCF
I would like to use interpolated strings in this old WCF project, and I have tried to change the target framework to .NET Framework 4.8 (from project pages). But this does not seem to change the C# version from 5 to 6.
I'm still getting the error
Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater.
Is this even possible?
Solution 1:[1]
You have to update language version in your .csproj file,
<PropertyGroup>
<LangVersion>6</LangVersion>
</PropertyGroup>
When you use language version as a 6, compiler accepts only syntax that is included in C# 6.0 or lower.
If you want to use any features which are included in higher or the latest version of C# like pattern matching, switch expression, global using then you can use <LangVersion>latest</LangVersion> instead of <LangVersion>6</LangVersion>.
More details, kindly check C# language version reference
Demo to update .csproj file:
Solution 2:[2]
edit the csproj: <LangVersion>6</LangVersion> (or higher); done
Solution 3:[3]
You can also and a LangVersion environment variable.
You can use https://aks.as/msbuildlog to debug your build.
Solution 4:[4]
Maybe you can also try to download the nuget package.
Microsoft.CodeDom.Providers.DotNetCompilerPlatform.
Replacement CodeDOM providers that use the new .NET Compiler Platform ("Roslyn") compiler as a service APIs. This provides support for new language features in systems using CodeDOM (e.g. ASP.NET runtime compilation) as well as improving the compilation performance of these systems.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Marc Gravell |
| Solution 3 | Paulo Morgado |
| Solution 4 | Lan Huang |

