Is it possible to use a C# 7 language feature, e.g. 'var mytuple = (1, 2);' in a .NET Framework 4.8 web application (no .NET Core/.NET7) without deploying Roslyn and without precompiling my web application?
Microsoft documentation says .NET Framework 4.8 supports C# 7.3, which led me to believe that is possible. According to Lex Li, the answer is 'No, not possible'. From his blog: "Starting from Visual Studio 2015, the 1.0 release of Roslyn based C# compiler became the default compiler, but Microsoft decided to make it part of Visual Studio (also as NuGet package), instead of being part of .NET Framework."
Seems Microsoft never changed that, and I need to deploy Roslyn or precomile everything or stay on C# 5.
== original question, only for readers who wonder what the discussion in the answers is about ==
In my .NET Framework 4.8 website with ASP.NET pages, I want to use features from C# 7. When I try, I get this compiler error:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" ...
Microsoft (R) Visual C# Compiler version 4.8.4084.0 for C# 5 This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5
It then suggests to use Roslyn. Bundling Roslyn within my website works - but unfortunately it causes problems on some older (Windows 2012) servers. I am looking for a solution without bundling Roslyn, without using NuGet to install Roslyn, or similar suggestions. I only want C# 7 support.
- According to the Microsoft documentation, all versions of .NET Framework support C# 7.3. Installing the latest .NET Framework 4.8.1 runtime did not help. The csc.exe is still the version that only supports up to C# 5.
- According to this SO issue, C# 7 should work out of the box in ASP.NET. But my page still says the compiler supports up to C# 5.
- I cannot add a <compiler> tag to Microsoft.CodeDom.Providers.DotNetCompilerPlatform in my web.config, because that is Roslyn and I do not have (or want) a Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll on the server.
Does anyone know if this is possible? Is there an installation that sets the csc.exe in C:\Windows\Microsoft.NET\Framework64 to a version that supports C# 7.3 as advertised?