Visual Studio 2015 not syntax highlighting razor n

2019-01-05 08:10发布

My Razor views in VS2015 RC are not showing the proper coloring for C# code. My project was working fine in VS2013, but it isn't in 2015, and it's not giving me any Intellisense on the C# code. The solution builds and the site runs fine.

I tried the following to no avail

  • disabling all Visual Studio extensions
  • deleting my .suo file
  • removing the project and re-adding it to the solution

How can I fix this?

Example:

21条回答
Anthone
2楼-- · 2019-01-05 08:30

Running VS 2015 RTM. Neither /ResetUserData nor /SafeMode worked for me. Also had some Productivity Power Tools 2015 related complains with "errors-in-ActivityLog.xml" popup when starting VS.

So, if you have similar symptoms, here's how I fixed it on my machine:

  1. Launch "Start Experimental Instance of Visual Studio 2015" and open your project. If the intellisense is working and razor syntax is highlighted, you have a great chances the following will work.
  2. Uninstall "Productivity Power Tools 2015" and close Visual Studio.
  3. Go to %LOCALAPPDATA%\Microsoft\VisualStudio\ and erase 14.0 folder.
  4. Launch VS - it should start as it was just installed.

P.S. Actually, it took me a couple times to get my intellisense working because I disabled the PowerTools first and it broke VS again when reenabled. So, it requires a complete reinstall. Might be caused by another extension in your case.

查看更多
爷的心禁止访问
3楼-- · 2019-01-05 08:34

I fixed this problem by updating my project to ASP .NET MVC version 5. But it required some futher manipulations with configuration files. Here I found the step-by-step guide:

  • in global.asax, change: WebApiConfig.Register(GlobalConfiguration.Configuration); to GlobalConfiguration.Configure(WebApiConfig.Register);
  • Make sure all the packages that your projects use are compatible with MVC 5 and Web API 2
  • Remove any of the following ASP.NET NuGet packages that are installed:
    1. Microsoft.AspNet.WebPages.Administration
    2. Microsoft-Web-Helpers (do not confuse with Microsoft.AspNet.WebHelpers !)
    3. Microsoft.AspNet.Mvc.FixedDisplayMode
  • Upgrade all the ASP.NET NuGet packages. In the Package Manager Console you can run the following command: Update-Package. Without any parameters it will update every package.
  • Update the Application and Views config Files:
    1. For all elements with the name attribute “System.Web.Mvc”, change the version number to new one (check version of assembly in solution explorer, it has to be equals to or higher than “5.0.0.0”)
    2. Do the same for all elements with the name attribute "System.Web.Helpers” and "System.Web.WebPages".
    3. Check binding redirects for assemblies "System.Web.Helpers", "System.Web.Mvc" and "System.Web.WebPages" in configuration files, "oldVersion" and "newVersion" must comply with the changes made above.
    4. Locate the appSettings section and update the webpages:version from "2.0.0.0.0" to "3.0.0.0"
    5. Update all elements that contain “System.Web.WebPages.Razor” from version “2.0.0.0” to version “3.0.0.0”. If this section contains “System.Web.WebPages”, update those elements from version “2.0.0.0” to version “3.0.0.0”
    6. If you removed the Microsoft-Web-Helpers NuGet package in a previous steps, install Microsoft.AspNet.WebHelpers with the following command in the Package Manager Console: Install-Package -Id Microsoft.AspNet.WebHelpers

I hope this will help.

查看更多
干净又极端
4楼-- · 2019-01-05 08:35

I had the same problem in VS 2015 RTM and was able to fix it by simply loading Visual Studio in Safe Mode by:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe /SafeMode

then closing and reopening it normally.

查看更多
beautiful°
5楼-- · 2019-01-05 08:36

Uninstalled and reinstalled of the following worked for me:

Microsoft.AspNet.Mvc

Microsoft.AspNet.WebPages

Microsfot.AspNet.Razor

I tried the reset userdata, deleting of temp and 14, as well as changing options settings and none of those worked. I even tried repaired and reinstalled. I am using VS 2015 Version 14.0.24720.00 Update 1

查看更多
我只想做你的唯一
6楼-- · 2019-01-05 08:36

A non-invasive approach is to check your Views web.config files for the correct Versions. These Web.config files are under app/Area/AreaName/Views or the general app/Views folders. They are different than the project Web.config file.

  • Make sure each Version in the type assembly strings matches your NuGet installed version
  • Make sure the Version in the factoryType assembly string matches your NuGet installed version

Here is an example for the latest as of the writing of this comment:

<configSections>
 <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
 <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
 <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
 </sectionGroup>
 </configSections>
<system.web.webPages.razor>
 <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
查看更多
兄弟一词,经得起流年.
7楼-- · 2019-01-05 08:37

What worked for me (VS 2015 Community) was the option suggested in this answer. Running cmd.exe as administrator, I ran the following:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe /setup
查看更多
登录 后发表回答