I've updated my ASP.NET Mvc 5 web application to use the new c# 8.0 features through Visual Studio 2019 and everything works fine until I try to use these new features inside a Razor view.
For example, if I try to use the new switch expression:
@{
ViewBag.Title = "About";
var foo = 1;
var bar = foo switch
{
1 => "one",
2 => "two",
_ => string.Empty
};
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
<p>Use this area to provide additional information.</p>
The compiler won't complain until I try to reach the page, giving me a compilation error.
I suspect that Microsoft.CodeDom.Providers.DotNetCompilerPlatform
must be updated but it seems that there is no update available.
Is there any way to use c# 8.0 language features in Razor views?