Razor Intellisense Not Working VS2010 SP1Rel MVC3

2019-01-18 21:27发布

I have Visual Studio 2010 /SP1 / MVC 3 (With April Tools Update) installed on a machine with a fresh install of Windows 7 64-bit Professional.

I do not have resharper installed. I never installed an RC or Beta of anything on this new OS Install.

My install steps were as follows:

  1. Install Visual Studio Professional.
  2. Install Web Platform Installer.
  3. Install Visual Studio SP1 from WPI.
  4. Install Microsoft ASP.net MVC 3 (with April Tools Update)
  5. Install Productivity Power Tools

Help > About Microsoft Visual Studio shows:

Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel

Microsoft .NET Framework Version 4.0.30319 SP1Rel

System.Web.Mvc.dll file version shows: 3.0.20105.0

Once installed I did the following:

  1. Open Visual Studio.
  2. File > New Project
  3. Choose "ASP.Net MVC 3 Web Application".
  4. On the "New ASP.NET MVC 3 Project" dialog. I chose "Internet Application", "Razor" View Engine. Hit OK.

Within the project here is the behavior:

  1. Open any cshtml file and Razor @blocks are not highlighted.
  2. Intellisense gives html snippets as options in and outside of razor blocks but does not recognize Html helpers or models etc within them.
  3. The project builds.
  4. You can run the project and everything works when built. Razor views are rendered normally.

Does anyone know a definitive set of prerequisites to have Razor Intellisense working? Something I can diff between the other Win7 64-bit machines that have Razor Intellisense working and the 2 that have this issue? Registry entries? Are there any Visual Studio logs that can help debug this? After hours of frustration and reading every Razor Intellisense post and question I have run across without coming up with anything that works I am just hoping for some new thoughts on what to troubleshoot/try next.

Thanks for any help on this.

12条回答
我想做一个坏孩纸
2楼-- · 2019-01-18 22:07

Please note that for me what caused the problem was the Roslyn Language Services plugin installed. When I uninstalled the plugin the issue was solved. To uninstall the plugin simply go to tools->extension manager and find the plugin Roslyn Language Services. Click the uninstall button and restart VS2010.

查看更多
叛逆
3楼-- · 2019-01-18 22:13

Razor Intellisense work with Razor Editor

Check if it is selected as default editor, For this do

  • Right Click on view file (.cshtml)
  • Select Open With...
  • Check Razor editor Select as default
  • if not, uninstall mvc3 from control panel reinstall it.

Again check files must be opened in Razor Editor. I have done this and its working now.

查看更多
Emotional °昔
4楼-- · 2019-01-18 22:16

I had this problem with one of my projects and the problem was the project somehow got converted to a Class Library project when I converted it from a standalone MVC app into an Orchard module.

Fixed by opening the .csproj file in a text editor and replacing this line:

<ProjectTypeGuids>{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

with this:

<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
查看更多
Bombasti
5楼-- · 2019-01-18 22:17

I fixed it by right clicking on the cshtml file and selecting "View Markup".

查看更多
放荡不羁爱自由
6楼-- · 2019-01-18 22:18

I was experiencing the same issue. It started to happen randomly when I changed the view engine in the Views web.config to a custom one. It is a known problem VS2010 Intellisense has issues with recognizing reserved words when custom view engine is in place or when a view inherits from a custom view page.

Everyone running into Razor Intellisense issues should check this out. None of the above fixes (reinstalling VS, rapplying SP1, reapplying MVC3 Tools Update) did help.

查看更多
Bombasti
7楼-- · 2019-01-18 22:20

If you have MVC4 and MVC3 installed you need to add this to appsettings in web.config (in root and in Views folder) to use MVC3

<appsettings>
    <add key="webpages:Version" value="1.0.0.0">
    ...
</appsettings>

Also check your references in root web.config, they should included these versions

<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Re-open your solution for settings to take effect

查看更多
登录 后发表回答