121

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:

DLeh
  • 23,806
  • 16
  • 84
  • 128
  • 3
    Have you considered waiting for a full release? The current one is still pretty buggy and is meant just as a preview for those impatient. – walther May 18 '15 at 19:29
  • Did you have installed the Productivity Tools ? In my case they crashed a lot in vs... Curretnly got now highlight in vNext PRojects – Boas Enkler Jul 22 '15 at 06:55
  • This is still occurring in VS2015 Professional. None of the answers in this thread solve the issue permanently. Syntax highlighting remains broken. – Justin Skiles Oct 28 '15 at 21:26
  • In case none of the answers below solves the issue, you may want to take a look here: http://stackoverflow.com/questions/33245041/visual-studio-thinks-microsoft-web-developer-tools-is-installed/37756993 Installing .NET Core 1.0.0 solved the issue for me. I started with the same issue, but also had a problem with the Web templates (not available for new projects). The check mark on "Microsoft Web Developer Tools" (as described in one of the answers below) was always checked. –  Jun 11 '16 at 06:08
  • Check your version of MVC. If it's 3 or less then VS 2015 doesn't support it. – RMuesi May 12 '17 at 00:36

21 Answers21

214

I've found in this answer another way to fix it without the devenv.exe /ResetUserData

Just delete the contents of this directory with Visual Studio closed: %LocalAppData%\Microsoft\VisualStudio\<visual_studio_version_number>\ComponentModelCache

To find the version number of the Visual Studio edition your are running please refer this list. Note that only the major number is important, the minor version can and will probably differ. In my case I had Visual Studio 2017 Enterprise installed so I looked for 15.xx and found 15.0_9a1c4a06 inside the AppData folder.

Jevgeni Geurtsen
  • 3,133
  • 4
  • 17
  • 35
fabriciorissetto
  • 9,475
  • 5
  • 65
  • 73
52

I had the same problem, the only fix so far is by resetting all user data (C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe /ResetUserData).

NOTE: You will lose all customizations, e.g. keyboard shortcuts and window layouts if you do this!

EDIT: People are saying this only works for RC, not RTM, so you might want to try the other fixes first.

Geir Sagberg
  • 9,632
  • 8
  • 45
  • 60
  • While this probably isn't the *best* solution, it worked for me! Thanks! I'm wondering if it had anything to do with having previous CTP versions installed. – DLeh May 19 '15 at 17:02
  • 2
    you can export the keybindings before, and restore them afterwards – quadroid May 19 '15 at 17:53
  • Is the '>' caret right in that command line? It worked for me by replacing that with a backwards slash. But this solution then worked for me as well! – Nicholas Petersen May 28 '15 at 21:33
  • 1
    And you loose all Addons. – Knerd Jul 11 '15 at 15:48
  • 1
    I have Enterprise version *(VS 2015)*. is there any possible solution for this version? above solution did not work for me. – Zeeshan Aug 06 '15 at 06:47
  • Also have the enterprise version - it did not work for me either. – Steve French Aug 13 '15 at 15:00
  • Didn't work for me. Reinstalling Web Tools manually fixed everything. You can get them here : https://www.microsoft.com/en-us/download/details.aspx?id=48222 – Marc-Andre R. Nov 03 '15 at 20:40
  • @Marc-AndreR. Tried that. I even tried updating VS2015 Update 1. It didn't do anything. – Justin Skiles Dec 08 '15 at 03:02
  • I Had bunch of problems after updating VS2015 PRO to update 1 (including syntax highlighting) and the /reserUserData + /safeMode described by @kevin just did the trick – Bruno Dec 10 '15 at 13:55
  • Yay! Worked for me thanks! (using VS2015 Professional Update1) – Aldracor Feb 12 '16 at 05:59
27

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.

Sruit A.Suk
  • 7,073
  • 7
  • 61
  • 71
Kevin
  • 749
  • 5
  • 10
10

After Updating Visual Studio 2015 Update 1 I had same issue. I tried all the answers but did not work for me.

The fix for me was going to programs and properties > Visual Studio community edition > Change. I clicked on modify.

In the list make sure to put a check mark on "Microsoft Web Developer Tools" under "Windows and Web Development" .

It was not checked in my list howewer :/

enter image description here

Bahtiyar Özdere
  • 1,818
  • 17
  • 21
  • Unfortunately when I tried this, the checkmark just came back. :< It refused to go away. :< Still stuck with this problem. :< Very ticked off at VS right now. :< huge time sink. – PHenry Jun 01 '16 at 02:03
  • Take a look here: http://stackoverflow.com/questions/33245041/visual-studio-thinks-microsoft-web-developer-tools-is-installed/37756993 The symptoms are the same. I solved this issue by installing .NET Core 1.0.0 –  Jun 10 '16 at 21:11
7

Tools > Options > Text Editor > All Languages > General. Uncheck the Hide advanced members option. Click OK.

Once I did that Intellisense seemed to work for me. I then reset it back and kept functionality. I'm using Visual Studio 2015 enterprise edition.

I had tried ResetUserData and that did not work for me.

Postmita
  • 71
  • 1
  • 2
6

I installed Visual Studio Community Edition 2015 (after using Visual Studio Community Edition 2013 for a long time) and faced the same issue. I tried all the above solutions but nothing helped.

Finally, close Visual studio and deleted the following folders -

C:\Users\Allwyn\AppData\Roaming\Microsoft\VisualStudio\14.0
C:\Users\Allwyn\AppData\Roaming\Microsoft\VisualStudio\14.0

... and it works now!!!

Allwyn Dsouza
  • 61
  • 2
  • 4
  • this worked for me (full release) VS 2015 Enterprise edition – hal9000 Oct 07 '15 at 20:52
  • Sometimes this works and sometimes it doesn't. It fixed it for me for about 5 minutes then it started happening again. – Justin Skiles Oct 28 '15 at 15:49
  • This fixed my issue at least for right now. It might not continue to work but we shall see. Seems like an odd error and something Microsoft should fix. This issue was in both 2015 and 2017 – Deathstalker Oct 10 '17 at 20:41
5

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.

4

This will be the effect if your project is MVC4. See more details here. Also note that this will be corrected in an upcoming release.
How can you tell if your project is MVC4? Open packages.config and scroll to the entry for Microsoft.AspNet.Mvc.  If the version listed starts with "4", this means you are using MVC 4.

Community
  • 1
  • 1
Van Kichline
  • 1,703
  • 1
  • 14
  • 15
4

I had a similar issue, where any razor script wouldn't be highlighted, intellisense wouldn't work and the compiler wouldn't recognise any errors (even where I intentionally put syntax errors in!)

I actually fixed the problem by going to C:/Users/YourUserName/AppData/Local/Temp and deleting everything out of this file, soon as I did that and restarted VS my Razor Views started to work!

Hope that helps!

  • This worked for me. I had to manually delete some items in the Razor-Server folder as well that were being locked up in the compile process. – Rudy Scoggins Nov 15 '19 at 16:20
3

Some views were working fine for me, some not at all... The only thing that helped for me:

  • Closing VS
  • Deleting C:\Users\%username%\AppData\Local\Temp
  • Restarting VS
  • Problem solved

I tried most of the other solutions, too, but they didn't work for me.

Roger
  • 76
  • 4
2

Friendly reminder to make sure you have correctly used the lowercase @model at the top of your view, and not @Model (like I made the mistake of doing).

Lowercase @model is a directive that strongly types the view to an instance of the class that follows it. Whereas the capitalized Model is a property of the view that gets the model instance.

Kevin Collins
  • 1,453
  • 1
  • 10
  • 16
1

I fixed the issue by including the file in the project/solution. I'd overlooked the fact that there's no highlighting/intellisense if it's not included.

Dave Clarke
  • 2,677
  • 4
  • 22
  • 35
0

I had the same problem and had to download and install "Microsoft ASP.NET and Web Tools" and "Web Essentials". After doing this syntax highlighting and Razor intellisense started working again.

Ogglas
  • 62,132
  • 37
  • 328
  • 418
0

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

wirble
  • 151
  • 1
  • 3
  • 16
  • This worked for me as well, I had an MVC4 site I had been working in VS2013 because of the lack of support until Update 1. After Update 1 was installed it was still not working in 2015, but uninstall and re-install of the packages from Nuget solved the problem. – lostatredrock Mar 04 '16 at 13:38
0

You should only remove the ".vs" folder in your project.(The .vs folder is hidden)

Be careful ResetUserData remove all customization on Visual Studio.

Fred
  • 3,365
  • 4
  • 36
  • 57
0

The only thing that worked for me was to change the project's "Output Path" to bin\ (It used to be bin\Debug):

  1. Right-click on the project,
  2. Click on Properties and navigate to Build,
  3. Scroll to the last section titled "Output",
  4. Change the value in the text box labeled Output path: to bin\
mono blaine
  • 1,001
  • 9
  • 13
0

Above doesn't work but I managed with:

  • Uninstalling (from Windows Program And Features) Web Developer Tools for VS 2015, RC, Update 1
  • Installing (from VS Installer -> Modify) Web Developer Tools (it's another version of above)

So the problem was that VS installer didn't install Web Developer Tools recognizing already installed, incompatible version as the proper one.

Krystian
  • 122
  • 1
  • 10
0

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.

0

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" />
gregsonian
  • 1,126
  • 13
  • 15
0

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
Community
  • 1
  • 1
OfirD
  • 9,442
  • 5
  • 47
  • 90
0

I have been downloading and installing "Microsoft ASP.NET and Web Tools" and "Web Essentials" and it worked for me.