Next & Previous

Visual Studio 2017 underlining all MVC code in red even though it builds

Build succeeded - OR DID IT?!

This project builds fine, but in VS 2017 it shows a lot of errors, which is counterproductive for developers.

The following is a reduced set of instructions from the long-titled Microsoft article, How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2

Fixing MVC Version references

You might not think you upgraded the project from an older MVC version. In our case, I assume that either the previous developers of this project did it at some time, or VS mucked it up all by itself (not unheard of)

We didn't have a Web API component to the system, so it was just MVC that needed work.

To find out your MVC version, in Solution Explorer: expand References, find System.Web.Mvc, right-click, Properties, and find 'Version'. Mine is

Fix the application web.config

Find all references to System.Web.Mvc in this file. Their bindingRedirect configurations should all look something like this:

<bindingRedirect oldVersion="" newVersion="" />

For System.Web.Helpers, System.Web.WebPages, it should be:

<bindingRedirect oldVersion="" newVersion="" />

That bit didn't actually affect us. The only bit we needed to change was in <appSettings>, the webpages:Version should be updated to

<add key="webpages:Version" value="" />

Fix the Views/web.config

This had more problems to fix in my instance:


Once you have done all this, close Visual Studio. Reopen it, clean, and build. This should fix your problems!

For more info, check out the following SO question; Visual Studio MVC 5 shows error but compiles and runs okay.

Hope it helps :)