简体   繁体   English

Visual Studio 2015 不是语法高亮剃刀,也不是 Intellisense

[英]Visual Studio 2015 not syntax highlighting razor nor Intellisense

My Razor views in VS2015 RC are not showing the proper coloring for C# code.我在 VS2015 RC 中的 Razor 视图没有为 C# 代码显示正确的颜色。 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.我的项目在 VS2013 中运行良好,但在 2015 年不是,并且它没有给我任何关于 C# 代码的智能感知。 The solution builds and the site runs fine.解决方案构建并且站点运行良好。

I tried the following to no avail我尝试了以下无济于事

  • disabling all Visual Studio extensions禁用所有 Visual Studio 扩展
  • deleting my .suo file删除我的.suo文件
  • removing the project and re-adding it to the solution删除项目并将其重新添加到解决方案中

How can I fix this?我怎样才能解决这个问题?

Example:例子:

I've found in this answer another way to fix it without the devenv.exe /ResetUserData我在此答案中找到了另一种无需devenv.exe /ResetUserData即可修复它的devenv.exe /ResetUserData

Just delete the contents of this directory with Visual Studio closed: %LocalAppData%\\Microsoft\\VisualStudio\\<visual_studio_version_number>\\ComponentModelCache只需在关闭 Visual Studio 的情况下删除此目录的内容: %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.要查找您正在运行的 Visual Studio 版本的版本号,请参阅 列表。 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.就我而言,我安装了 Visual Studio 2017 Enterprise,因此我查找了15.xx并在 AppData 文件夹中找到了15.0_9a1c4a06

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 ).我遇到了同样的问题,目前唯一的解决方法是重置所有用户数据( C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\devenv.exe /ResetUserData )。

NOTE: You will lose all customizations, eg 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.编辑:人们说这仅适用于 RC,不适用于 RTM,因此您可能想先尝试其他修复程序。

I had the same problem in VS 2015 RTM and was able to fix it by simply loading Visual Studio in Safe Mode by:我在 VS 2015 RTM 中遇到了同样的问题,并且能够通过简单地在安全模式下加载 Visual Studio 来解决它:

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

then closing and reopening it normally.然后正常关闭并重新打开它。

After Updating Visual Studio 2015 Update 1 I had same issue.更新 Visual Studio 2015 Update 1 后,我遇到了同样的问题。 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.对我来说,修复程序和属性 > Visual Studio 社区版 > 更改。 I clicked on modify.我点击了修改。

In the list make sure to put a check mark on "Microsoft Web Developer Tools" under "Windows and Web Development" .在列表中确保勾选“Windows 和 Web 开发”下的“ Microsoft Web 开发工具”。

It was not checked in my list howewer :/它没有在我的列表中检查,但是:/

在此处输入图片说明

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.一旦我这样做了,Intellisense 似乎对我有用。 I then reset it back and kept functionality.然后我将其重置并保留功能。 I'm using Visual Studio 2015 enterprise edition.我正在使用 Visual Studio 2015 企业版。

I had tried ResetUserData and that did not work for me.我曾尝试过 ResetUserData 但这对我不起作用。

I installed Visual Studio Community Edition 2015 (after using Visual Studio Community Edition 2013 for a long time) and faced the same issue.我安装了 Visual Studio Community Edition 2015(在长时间使用 Visual Studio Community Edition 2013 之后)并遇到了同样的问题。 I tried all the above solutions but nothing helped.我尝试了上述所有解决方案,但没有任何帮助。

Finally, close Visual studio and deleted the following folders -最后,关闭 Visual Studio 并删除以下文件夹 -

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

... and it works now!!! ......它现在起作用了!!!

Running VS 2015 RTM.运行 VS 2015 RTM。 Neither /ResetUserData nor /SafeMode worked for me. /ResetUserData 和 /SafeMode 都不适合我。 Also had some Productivity Power Tools 2015 related complains with "errors-in-ActivityLog.xml" popup when starting VS.在启动 VS 时,还有一些与 Productivity Power Tools 2015 相关的抱怨和“errors-in-ActivityLog.xml”弹出窗口。

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.启动“启动 Visual Studio 2015 的实验实例”并打开您的项目。 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.卸载“Productivity Power Tools 2015”并关闭 Visual Studio。
  3. Go to %LOCALAPPDATA%\\Microsoft\\VisualStudio\\ and erase 14.0 folder.转到%LOCALAPPDATA%\\Microsoft\\VisualStudio\\并擦除14.0文件夹。
  4. Launch VS - it should start as it was just installed.启动 VS - 它应该在刚安装时启动。

PS 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. PS 实际上,我花了几次才让我的智能感知工作,因为我首先禁用了 PowerTools,重新启用时它再次破坏了 VS。 So, it requires a complete reinstall.因此,它需要完全重新安装。 Might be caused by another extension in your case.可能是由您的情况下的另一个扩展引起的。

This will be the effect if your project is MVC4.如果您的项目是 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?如何判断你的项目是否是MVC4? Open packages.config and scroll to the entry for Microsoft.AspNet.Mvc.打开packages.config 并滚动到Microsoft.AspNet.Mvc 的条目。 If the version listed starts with "4", this means you are using MVC 4.如果列出的版本以“4”开头,则表示您使用的是 MVC 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!我实际上通过转到 C:/Users/YourUserName/AppData/Local/Temp 并删除此文件中的所有内容来解决该问题,一旦我这样做并重新启动 VS,我的 Razor 视图就开始工作了!

Hope that helps!希望有帮助!

Some views were working fine for me, some not at all... The only thing that helped for me:有些观点对我来说效果很好,有些则完全没有......唯一对我有帮助的东西:

  • Closing VS收官VS
  • Deleting C:\\Users\\%username%\\AppData\\Local\\Temp删除 C:\\Users\\%username%\\AppData\\Local\\Temp
  • Restarting VS重启VS
  • Problem solved问题解决了

I tried most of the other solutions, too, but they didn't work for me.我也尝试了大多数其他解决方案,但它们对我不起作用。

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).友情提示,确保您在视图顶部正确使用了小写的@model ,而不是@Model (就像我犯的错误)。

Lowercase @model is a directive that strongly types the view to an instance of the class that follows it.小写@model是一个指令,它将视图强类型@model跟随它的类的实例。 Whereas the capitalized Model is a property of the view that gets the model instance.而大写的Model是获取模型实例的视图的属性。

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.我忽略了一个事实,即如果不包括在内,就没有突出显示/智能感知。

I had the same problem and had to download and install "Microsoft ASP.NET and Web Tools" and "Web Essentials".我遇到了同样的问题,不得不下载并安装“Microsoft ASP.NET and Web Tools”和“Web Essentials”。 After doing this syntax highlighting and Razor intellisense started working again.完成此语法突出显示后,Razor 智能感知再次开始工作。

In my Web.config I had this: 在我的Web.config中我有这个:

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
          <namespaces>
            <add namespace="LinkApp.Models.Templates"/>
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Optimization"/>
            <add namespace="System.Web.Routing" />
            <add namespace="LinkApp" />
          </namespaces>
        </pages>
      </system.web.webPages.razor>

Oddly enough, I moved my custom namespace to the bottom, and that fixed it, like this:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="LinkApp" />
        <add namespace="LinkApp.Models.Templates"/>
      </namespaces>
    </pages>
  </system.web.webPages.razor>

Uninstalled and reinstalled of the following worked for me:卸载并重新安装以下对我有用:

Microsoft.AspNet.Mvc微软.AspNet.Mvc

Microsoft.AspNet.WebPages Microsoft.AspNet.WebPages

Microsfot.AspNet.Razor Microsfot.AspNet.Razor

I tried the reset userdata, deleting of temp and 14, as well as changing options settings and none of those worked.我尝试了重置用户数据,删除 temp 和 14,以及更改选项设置,但这些都不起作用。 I even tried repaired and reinstalled.我什至尝试修复并重新安装。 I am using VS 2015 Version 14.0.24720.00 Update 1我正在使用 VS 2015 版本 14.0.24720.00 更新 1

You should only remove the ".vs" folder in your project.(The .vs folder is hidden)您应该只删除项目中的“.vs”文件夹。(隐藏 .vs 文件夹)

Be careful ResetUserData remove all customization on Visual Studio.小心ResetUserData删除 Visual Studio 上的所有自定义。

The only thing that worked for me was to change the project's "Output Path" to bin\\ (It used to be bin\\Debug ):唯一对我有用的是将项目的“输出路径”更改为bin\\ (它曾经是bin\\Debug ):

  1. Right-click on the project,右键单击项目,
  2. Click on Properties and navigate to Build ,单击Properties并导航到Build
  3. Scroll to the last section titled "Output",滚动到最后一个标题为“输出”的部分,
  4. Change the value in the text box labeled Output path: to bin\\将标记为Output path:的文本框中的值更改为bin\\

Above doesn't work but I managed with:以上不起作用,但我设法:

  • Uninstalling (from Windows Program And Features) Web Developer Tools for VS 2015, RC, Update 1卸载(从 Windows 程序和功能)适用于 VS 2015、RC、更新 1 的Web Developer Tools
  • Installing (from VS Installer -> Modify) Web Developer Tools (it's another version of above)安装(从 VS 安装程序 -> 修改) Web Developer Tools (这是上面的另一个版本)

So the problem was that VS installer didn't install Web Developer Tools recognizing already installed, incompatible version as the proper one.所以问题是 VS 安装程序没有安装 Web 开发工具,将已经安装的不兼容版本识别为正确的版本。

I fixed this problem by updating my project to ASP .NET MVC version 5. But it required some futher manipulations with configuration files.我通过将我的项目更新到 ASP .NET MVC 版本 5 解决了这个问题。但它需要对配置文件进行一些进一步的操作。 Here I found the step-by-step guide: 在这里,我找到了分步指南:

  • in global.asax, change: WebApiConfig.Register(GlobalConfiguration.Configuration);在 global.asax 中,更改: WebApiConfig.Register(GlobalConfiguration.Configuration); to GlobalConfiguration.Configure(WebApiConfig.Register);GlobalConfiguration.Configure(WebApiConfig.Register);
  • Make sure all the packages that your projects use are compatible with MVC 5 and Web API 2确保您的项目使用的所有包都与 MVC 5 和 Web API 2 兼容
  • Remove any of the following ASP.NET NuGet packages that are installed:删除以下任何已安装的 ASP.NET NuGet 包:
    1. Microsoft.AspNet.WebPages.Administration Microsoft.AspNet.WebPages.Administration
    2. Microsoft-Web-Helpers ( do not confuse with Microsoft.AspNet.WebHelpers ! ) Microsoft-Web-Helpers(不要与 Microsoft.AspNet.WebHelpers 混淆!
    3. Microsoft.AspNet.Mvc.FixedDisplayMode Microsoft.AspNet.Mvc.FixedDisplayMode
  • Upgrade all the ASP.NET NuGet packages.升级所有 ASP.NET NuGet 包。 In the Package Manager Console you can run the following command: Update-Package .在包管理器控制台中,您可以运行以下命令: 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”)对于名称属性为“System.Web.Mvc”的所有元素,将版本号更改为新的(在解决方案资源管理器中检查程序集版本,它必须等于或高于“5.0.0.0”)
    2. Do the same for all elements with the name attribute "System.Web.Helpers” and "System.Web.WebPages" .对名称属性为"System.Web.Helpers""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.检查配置文件中程序集“System.Web.Helpers”“System.Web.Mvc”“System.Web.WebPages”的绑定重定向,“oldVersion”和“newVersion”必须符合上述更改。
    4. Locate the appSettings section and update the webpages:version from "2.0.0.0.0" to "3.0.0.0"找到appSettings部分并更新网页:版本从“2.0.0.0.0”到“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”.将包含“System.Web.WebPages.Razor”的所有元素从“2.0.0.0”版本更新到“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”如果此部分包含“System.Web.WebPages” ,请将这些元素从“2.0.0.0”版本更新为“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如果您在前面的步骤中删除了Microsoft-Web-Helpers NuGet 包,请在包管理器控制台中使用以下命令安装Microsoft.AspNet.WebHelpersInstall-Package -Id Microsoft.AspNet.WebHelpers

I hope this will help.我希望这将有所帮助。

A non-invasive approach is to check your Views web.config files for the correct Versions.一种非侵入性的方法是检查您的视图 web.config 文件以获取正确的版本。 These Web.config files are under app/Area/AreaName/Views or the general app/Views folders.这些 Web.config 文件位于 app/Area/AreaName/Views 或常规 app/Views 文件夹下。 They are different than the project Web.config file.它们与项目 Web.config 文件不同。

  • Make sure each Version in the type assembly strings matches your NuGet installed version确保类型程序集字符串中的每个版本与您的 NuGet 安装版本匹配
  • Make sure the Version in the factoryType assembly string matches your NuGet installed version确保 factoryType 程序集字符串中的版本与您的 NuGet 安装版本匹配

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

What worked for me (VS 2015 Community) was the option suggested in this answer.对我有用的(VS 2015 社区)是这个答案中建议的选项。 Running cmd.exe as administrator, I ran the following:以管理员身份运行 cmd.exe,我运行了以下命令:

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

我一直在下载和安装“Microsoft ASP.NET and Web Tools”和“Web Essentials”,它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM