I am testing Visual Studio 2015 with C# 6.0 but the language features are not working. In an MVC web application, the following code does compile:
if (!string.IsNullOrWhiteSpace(Model.Profile?.TypeName))
{
// More logic here...
}
However, when I run the application via Debug and IIS Express, I get the following error:
CS1525: Invalid expression term '.'
How do I enable these features?
This works in MVC 5 (tested 5.2.3), you just need to add the roslyn code dom Nuget package
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.
PM> Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/