Enabling C# 7.0 in MVC 5 applications

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 the next packages:

Install<span class="token operator">-</span>Package Microsoft<span class="token punctuation">.</span>Net<span class="token punctuation">.</span>Compilers
PowerShell

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 

Good luck!

<system.codedom> 
    <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" type="..." warningLevel="4" compilerOptions="/langversion:7 /nowarn:1659;1699;1701" />
         ... 
        </compilers>
</system.codedom>
Author: Daniel Costea
Trainer. Developer. Speaker. Microsoft MVP.