Intellisense in razor/cshtml files not working (Visual Studio 2022)
Asked Answered
P

2

17

We are used to intellisense everywhere and suddenly it doesn't work.

To my frustration, this was only the case on my work computer, the installation at home does work. Both has been updated to version 17.5.0, but I think the problem also existed with the previous version (on my work computer) - it's been a while since I did any Razor coding.

I've searched for like issues, but every question were related to older versions of VS.

I finally found a mention of a new version of the Razor editor, with description of how to deactivate this and reactivate the old one. To my surprise this worked:

Open Tools / Options and navigate to Text Editor / HTML / Advanced, here you find a setting: "Use legacy Razor editor for ASP.NET CORE". Change the setting to true and intellisense are back!

Nice to find a solution, but!

  • This is just a work-around - there must be something else wrong with the installation on my work computer.
  • There is a team working on a new Razor editor - it would be nice to use this new (and hopefully) improved version.

Any suggestions how to actually solve this (not just work-around), will be appreciated!

Philipines answered 24/2, 2023 at 15:48 Comment(4)
1. Send feedback through VS. The product team can help try to track this down and the logs included in that feedback help. 2. Check for errors in the Output window, it may be an issue like developercommunity.visualstudio.com/t/… (root cause, antivirus was causing the language server to fail to start)Wiser
Indeed, did you solve it? I think I have the same problem. But with a fresh Visual Studio 2022 install (VS 17.8.1).Predict
I haven't had the time to look into the problem, so no - no solution just yet, The problem exists also in a fresh install of Visual Studio - quite annoying...Philipines
This did fix it to me perfectly. Visual Studio 2022.Pouch
P
10

OK - finally an update to handle this issue!

Update Visual Studio to 17.8.+ (.Net 8/C# 12 etc) - in this version they (the Visual Studio team) has included a setting to enable colors for the new Razor editor, see the release notes here!

If you has activated to old editor, deactivate: Tools/Options/Text Editor/HTML/Advanced - Set Razor setting to false (restart VS).

To activate colors: Tools/Options/Text Editor/Razor (Asp.NET Core)/Advanced - Set Background for C# code to true.

By the way: This setting defaults to false, so not active on new installations!

Philipines answered 8/12, 2023 at 11:57 Comment(6)
I am on 17.8. I have upgraded my Blazor .NET 7 project to .NET 8 and the new setting (Set Background for C# code) did not solve the problem - I need to use the old setting to make things right. When I create a new Blazor Web App everything is fine.Photodisintegration
I am on 17.9.5 and Tools/Options/Text Editor/HTML is not displayed and neither is Tools/Options/Text Editor/Razor. Is there anything else that is needed for these to be displayed?Krasnoyarsk
@Krasnoyarsk (and others): Sorry - I can only tell, what worked for me. Apparently "they" have removed the setting - it might have been moved somewhere else or simply disappeared.Philipines
@Krasnoyarsk It still exists (v17.9.6). In the options dialog (Tools>Options) search for HTML. It should be easy to find in the tree and it has a child node Advanced, with the mentioned option. And indeed, it brings back intellisense.Attack
I will install project and item templates to get the HTML and Razor options to display #73299203Krasnoyarsk
Switching to True and False back with restarts of VS solved my issue after updating project to .NET 8Palmieri
D
-3

Since same VS version on your two computers, and the performance are different, I suggest you to follow the below steps to correct the un-normal one:

1, repair the VS:

open your visual studio installer:

enter image description here

click More -> Repair to repair the VS2022:

enter image description here

2, Reset the default settings

1'' Make sure not effected by the settings of the async user's settings, please turn off the user settings async:

enter image description here5

enter image description here

2'' Reset the language environment collection settings:

enter image description here

enter image description here

enter image description here

enter image description here

By the way, see whether all of your solutions in the un-normal VS have this issue.

If only one solution have this issue, that should comes from the intelliSense data of the solution.

Follow the below steps to regenerate the intelliSense data:

1, Close your VS2022

2, Open the root folder of the solution, delete the .vs folder(intelliSense data are in this place):

enter image description here

3, Reopen the VS2022, wait for the regenerate steps finished and try test the intelliSense again.

Didynamous answered 27/2, 2023 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.