Visual Studio 2017 cshtml file errors

2019-05-17 09:35发布

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

3条回答
2楼-- · 2019-05-17 09:47

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

查看更多
对你真心纯属浪费
3楼-- · 2019-05-17 09:52

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

查看更多
老娘就宠你
4楼-- · 2019-05-17 10:10

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.

查看更多
登录 后发表回答