6

I opened my existing VS2015 solution in the new VS2017. Was hoping it would just work, however, I am seeing a lot of red lines under words like - @model, @ViewBag, @ActionLink, @Url, @Partial, @Scripts, @Styles, and under lambda expressions in the where clause on the model for the page.

Not sure what is missing or wrong. The solution builds, but shows errors in the cshtml files.

Anyone help or direction would be helpful.

Thanks in advance. Ken

Ken Cronin
  • 61
  • 1
  • 2
  • 3
    Have you tried reopening the file a few times, or restarting the editor? This happens all the time for me in 2015, haven't gotten the chance to try 2017 yet though. – Scott Mar 09 '17 at 21:40
  • Can you share more details about what type of project these are in? – Jimmy Mar 09 '17 at 22:04
  • My solution contains an MVC project targeting .NET framework 4.5.2. I know in the past there were issues with the Razor files missing references, etc. Was just wondering if anyone else was having the same issue. – Ken Cronin Mar 13 '17 at 21:58
  • I figured out the issue. I was on ASP.NET MVC 4 and needed to move to ASP.NET MVC 5, then everything worked perfectly. This is the link I followed... https://learn.microsoft.com/en-us/aspnet/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2 – Ken Cronin Apr 06 '17 at 20:53

3 Answers3

3

I had this issue and https://stackoverflow.com/a/19696998/4484478 fixed it for me. My solution was created with VS2012. I started using VS2013 and VS2015 to work on this solution after RTM came out and the issue OP described occurred after I started using VS2017.

From the answer post:

Create a new project targeting same .NET framework and copy its Views/web.config file over top the one in your current project.

Note that the web.config here is the one inside the Views folder and not the main one. This is probably the simplest way to fix it. But if you have some other customization in this file you can try editing manually the version numbers for Razor and MVC. Mine changed from 2.0.0.0 -> 3.0.0.0 for Razor

enter image description here

And 4.0.0.0 -> 5.2.3.0 for MVC enter image description here

enter image description here

Community
  • 1
  • 1
noriMonsta
  • 2,507
  • 2
  • 11
  • 7
  • 2
    Please convert your images to formatted code blocks. It's different to see exactly what you're changing because some of it is cut off, and it's impossible to copy/paste any of it. – jpmc26 Jan 17 '18 at 21:03
  • Also had to update the web.config in the views folder to reference the namespace of my website. Both creating a new project and altering the namespace reference finally fixed it. – Kevin M Jun 27 '18 at 15:09
1

in my case it turned out to be a version in solution (.sln) file.

up top, i replaced my version with the following:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.0
MinimumVisualStudioVersion = 10.0.40219.1

best way to go about this is create a new solution in your VS of choice, and then compare the .sln files, and copy the version parts from working file.

Sonic Soul
  • 23,855
  • 37
  • 130
  • 196
1

For the project giving the errors, verify the top line of the .csproj file is <Project Sdk="Microsoft.NET.Sdk.Web"> as that was tripping up my View related files. Before the change, that line read <Project Sdk="Microsoft.NET.Sdk">

Ryan Rodemoyer
  • 5,548
  • 12
  • 44
  • 54