特定 Web 应用程序 (VS2015) 中没有 javascript 智能感知

no javascript intellisense in a particular web application (VS2015)

在我的一个解决方案中,我有一个 class 库项目和两个 Web 应用程序。在 Web 应用程序中,在 .cshtml 页面上,我有 Razor intellisense,但 Javascript 绝对没有。如果我输入“$”。然后按 ctrl+space,没有任何反应。没有弹出窗口。这非常令人沮丧,因为我对 JS 不是很熟悉!但是,在使用 Web 应用程序的不同解决方案中,我 do 具有 javascript 智能感知。这让我觉得不是 Visual Studio 坏了。这是关于这个特定解决方案的事情。这使得这个问题在其他类似的 Whosebug 问题中独一无二。

我已经尝试了在 Whosebug 上找到的所有答案。尤其是大家的最爱,将/Scripts/_reference.js文件添加到工具|选项 |代码编辑器 | Javascript |智能感知设置。那没有帮助。我已尝试将 jQuery 从 3.1.1 降级到 2.x,该版本与解决方案中使用的版本相同。我尝试编辑 _reference.js 文件以减少项目。我禁用了 Resharper。我已经卸载并重新加载了项目。我已经重新启动VS。我没有重置VS的设置,因为那样太乱了,而且因为它在其他项目中有效,我不想。

我需要的是了解 Visual Studio 如何确定如何显示 intellisense 的人,以便为我提供一份清单,列出需要到位才能正常工作的事项。这里的关键线索是为什么一个解决方案可以正常工作而另一个不能?什么样的项目级别设置会对此产生影响?

这是我的 /Scripts/_references.js 文件:

/// <autosync enabled="false" />
/// <reference path="jquery-3.1.1.js" />
/// <reference path="jquery-3.1.1.intellisense.js" />
/// <reference path="jquery-ui-1.11.4.js" />
/// <reference path="bloodhound.js" />
/// <reference path="bootstrap.js" />
/// <reference path="jquery.countdown.js" />
/// <reference path="jquery.unobtrusive-ajax.js" />
/// <reference path="jquery.validate.js" />
/// <reference path="jquery.validate.unobtrusive.js" />
/// <reference path="jquery-ui-timepicker-addon.js" />
/// <reference path="modernizr-2.8.3.js" />
/// <reference path="respond.js" />
/// <reference path="typeahead.bundle.js" />
/// <reference path="typeahead.jquery.js" />
/// <reference path="typeahead.mvc.model.js" />

@sara-msft 在 visual studio 论坛上帮助我解决了这个问题,我会在这里重新发布信息以帮助其他人。首先,她给了我一些很棒的尝试步骤:

Refer to your description, this issue only happens in this solution. We need to check if this issue existing for all .cshtml files among this solution or not, please have a look at the following to troubleshot: (Back up the solution before any modification, in case we need to roll back. )

  1. Add a new .cshtml file under the same web page or another web page project to test the intellisense

  2. Add a new web application, then add a new .cshtml file under this new web application and check

  3. Remove the class library project and web application project one by one to check if the other project affects this issue

Meanwhile, you can try the following methods which usually work for the intellisense not working issue:

  1. Delete the .suo or .vs file under your solution folder, the .vs folder might be hidden, restart VS and reopen this solution to check this issue again.

  2. In your _references.js file, ‘autosync’ is ‘false’, the default value is ‘true’, you can also modify it and clean up the solution, rebuild it, then test the intellisense again

  3. Right click the .cshtml file an choose ‘Open with…’ and it should be ‘HTML Editor (Default)’.

  4. Try to open an administrative CMD window and navigate to C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE and run the commands: devenv /resetuserdata to clean up the old user data. 5. Delete or rename the folders: C:\Users\AppData\Local\Microsoft\VisualStudio.0 and C:\Users\AppData\Roaming\Microsoft\VisualStudio.0 to clean up the cache data.

我在第 2 步取得了成功。

2。添加一个新的web应用,然后在这个新的web应用下添加一个新的.cshtml文件并勾选

我认为这意味着向损坏的解决方案添加一个新的应用程序,所以我这样做了。 JS Intellisense 在这个新项目中起作用!这是一个很棒的尝试。它以 JQuery 1.x 开头,我升级到 3.1.1 以匹配其他项目。这削弱了智能感知的质量,只提供最少量的信息。我看了一下 _references.js,发现只有 jquery.min.* 和 jquery.slim.* 文件存在。我删除了这些引用并将其更改为 jquery-3.1.1.js 文件。所以我的 ~/Scripts/_references.js 看起来像这样:

/// <autosync enabled="true" />
/// <reference path="jquery-3.1.1.js" />
/// <reference path="bootstrap.js" />
/// <reference path="jquery.validate.js" />
/// <reference path="jquery.validate.unobtrusive.js" />
/// <reference path="modernizr-2.6.2.js" />
/// <reference path="respond.js" />

这大大提高了 JS 智能感知的质量,因为它没有使用缩小版本,而且它也从 jquery-3.1.1.intellisense.js 文件中读取。

但是!我的其他项目呢?我复制了上面的 _references.js 代码并将其粘贴到损坏项目中的 _references.js 中。有用!耶!但是为什么?

我开始从损坏的 _references.js 文件中删除个别行。我没多久就找到了罪魁祸首。

/// <reference path="jquery-ui-1.11.4.js" />

这个引用破坏了我所有的 javascript 智能感知。删除它解决了我的问题。感谢 Sara 帮助解决此问题!

更新:我应该补充一点,有问题的参考并不是唯一会破坏智能感知的参考。我也找到了其他人,尤其是 KendoUI。因此,如果您遇到此问题,请开始删除 _references.js 中的引用,直到 javascript 再次起作用。