Enabling C# 7.0 in MVC 5 applications

May 15, 2017 C# 0 Comments

If you reached this post it’s pretty sure you encountered some problems using C# 7 features in Visual Studio 2017 MVC 5 applications.

After some investigation I have found a solution. Follow these steps:

Step 1. Open NuGet console and install next packages:

Install-Package Microsoft.Net.Compilers

Step 2. Set up the Properties->Build->Advanced->Language version to C# 7.0

Step 3. Open web.config file and locate compiler language section and update the attribute compileOptions from /langversion:6 to /langversion:7 

<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="..." warningLevel="4" compilerOptions="/langversion:7 /nowarn:1659;1699;1701" />
...
</compilers>
</system.codedom>

Good luck!