Razor智能感知在VS 2015中无法工作

24
当我在2015年打开我的VS2013项目时,所有的razor视图都会出现红色波浪线。
@model,@Scripts @url,@Html.Partial,lambda表达式
智能感知现在似乎没什么用处,因为它好像缺少一半的选项。
我看到的解决方案包括删除.vs文件夹和devenv.exe /ResetUserData,但这些对我不起作用。
我正在使用与我的同事相同的安装文件进行VS 2015社区版的全新安装。他们中没有人遇到razor问题,而且他们正在处理与我相同的项目。
有什么办法可以解决这个问题吗?
编辑...更多信息! 我卸载/重新安装了VS 2015社区版,打开了我的项目,razor工作了! 然后我点击了一个提示,要求更新NuGet。NuGet更新安装后,VS重新启动,razor再次停止工作。所以NuGet更新破坏了razor??
每次我打开一个razor文件时,它都会显示“遇到异常。这可能是由于扩展引起的。您可以通过检查文件'C:\Users\Jonathan\AppData\Roaming\Microsoft\VisualStudio\14.0\ActivityLog.xml'来获取更多信息。 ”
在活动日志中,我得到以下错误。
"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Item has already been added. Key in dictionary: 'RazorSupportedRuntimeVersion' Key being added: 'RazorSupportedRuntimeVersion' at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at System.Collections.Hashtable.Add(Object key, Object value) at System.Collections.Specialized.HybridDictionary.Add(Object key, Object value) at Microsoft.VisualStudio.Utilities.PropertyCollection.AddProperty(Object key, Object property) at Microsoft.VisualStudio.Html.Package.Razor.RazorVersionDetector.Microsoft.Html.Editor.ContainedLanguage.Razor.Def.IRazorVersionDetector.GetVersion(ITextBuffer textBuffer) at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorUtility.TryGetRazorVersion(ITextBuffer textBuffer, Version& razorVersion) at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorErrorTagger..ctor(ITextBuffer textBuffer) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) at System.Activator.CreateInstance(Type type, Object[] args) at Microsoft.Html.Editor.ContainedLanguage.Common.ContainedCodeErrorTaggerProvider`1.CreateTagger[T](ITextBuffer textBuffer) at Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator`1.GatherTaggers(ITextBuffer textBuffer)"

我该如何解决这个问题?


2
我有同样的问题,我不得不回到使用VS 2013... - Guigui
很奇怪。我已经读了很多人遇到这个问题,但是没有解决方案适用于某些情况。我打开的一些项目可以完美地工作,但大多数都不能。然而,对于我的同事们,它们都能正常工作。我已经切换回使用VS 2013来处理那些在2015中无法工作的项目 :( - mejobloggs
1
在我的电脑上,即使使用CodeDom编译器,在VS2015上一切都正常工作。然后,突然间,在UI中加载脚本时开始出现“System.Reflection.TargetInvocationException…”错误。一切仍然可以编译和正常工作,但我不能像这样操作。我正在追溯我的步骤,看看是否有任何扩展程序引起了这个问题,但这非常令人沮丧和低效! - HumbleBeginnings
1
在VS2015 Professional上进行了完全修复。甚至无法显示没有安装扩展的全新项目Razor!啊! - HumbleBeginnings
可能是Visual Studio 2015破损的Razor智能感知的重复问题。 - Mormegil
可能是Visual Studio 2015未对Razor进行语法高亮或智能感知的重复问题。 - fabriciorissetto
14个回答

0

我正在使用VS 2015专业版。遇到了同样的问题,尝试了上面提到的所有解决方案,但都没有起作用。无论是“devenv.exe /ResetUserData”还是“删除ComponentModelCache的内容”。

我唯一成功解决这个问题的方法是修改安装方式: 进入“程序和功能”->找到Microsoft Visual Studio ... 2015->点击更改->选择修改->勾选“Microsoft Web Developer Tools”->点击更新

这对我有用。


0

我已经阅读了很多解决方案,浪费了很多时间,当我确信无法解决 Visual Studio 2015 智能感知问题时,突然有人给出了正确的解决方案:

  1. C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE>devenv /updateco nfiguration
  2. C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE>devenv /clearcac he

重新启动 Visual Studio 可能会要求重新安装某些损坏的工具。好吧,你这样做了,但是从现在开始你的智能感知又可以正常工作了。祝大家好运,非常感谢 Nadir。


-1

只需执行以下操作:

工具 > 扩展和更新 > 更新 Visual Studio 版本

这可能需要一些时间,但之后工作将正常运行。


-2

在程序的第一行上设置一个断点

几秒钟后把它移除……这样肯定可以正常运行


ASP.NET MVC 中没有页面类。你是什么意思? - slfan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接