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-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 

Good luck!

Author: Daniel Costea
Trainer. Developer. Speaker. Microsoft MVP.