C# 6.0 Features Not Working with Visual Studio 2015

Chris Schiffhauer picture Chris Schiffhauer · Jan 15, 2015 · Viewed 46.5k times · Source

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?

Answer

jbtule picture jbtule · Jul 21, 2015

This works in MVC 5 (tested 5.2.3), you just need to add the roslyn code dom Nuget package

CodeDOM Providers for .NET Compiler...

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/