node.js 如何在 Visual Studio 2015 中禁用 NPM 包还原?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31876984/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 19:13:43  来源:igfitidea点击:

How can I disable NPM package restore in Visual Studio 2015?

node.jsvisual-studionpmvisual-studio-2015

提问by Geir Sagberg

When I open a project with a package.json in Visual Studio 2015, an npm install is automatically started, and VS is unresponsive until the install is completed.

当我在 Visual Studio 2015 中打开一个带有 package.json 的项目时,会自动启动 npm install,并且 VS 在安装完成之前没有响应。

I would much rather prefer running npm install myself from the command line; how can I stop Visual Studio from doing it?

我更喜欢从命令行运行 npm install 自己;我怎样才能阻止 Visual Studio 这样做?

采纳答案by Rich N

If you upgrade to Visual Studio 2017 (the free 'Community Edition' is fine) then the VS team have added an option to stop npm running when a project is opened. It's under Tools/Options/Projects and Solutions/Web Package Management/Package Restore. You can disable NPM (and Bower) restores on Project Open and on package.json Save separately.

如果您升级到 Visual Studio 2017(免费的“社区版”很好),那么 VS 团队会添加一个选项来在项目打开时停止运行 npm。它位于工具/选项/项目和解决方案/Web 包管理/包还原下。您可以分别在 Project Open 和 package.json Save 上禁用 NPM(和 Bower)还原。

Note also that for the node.js project types (NTVS) onlythe automatic package restore behavior is disabled completely in VS2017 at present.

另请注意,对于 node.js 项目类型 ( NTVS),目前在 VS2017 中完全禁用了自动包还原行为。

Edit: the above answer also applies to Visual Studio 2019. The menu options are in the same place, although Bower support has been deprecated.

编辑:上述答案也适用于 Visual Studio 2019。菜单选项位于同一位置,尽管 Bower 支持已被弃用。

回答by Van Kichline

Try this:

尝试这个:

  • Open Tools -> Options
  • Select Projects and Solutions / External Web Tools
  • Uncheck all four paths
  • Click OK
  • 打开工具 -> 选项
  • 选择项目和解决方案/外部网络工具
  • 取消选中所有四个路径
  • 单击确定

It doesn't seem that closing the solution, etc., is necessary. NPM and Bower functionality are now disabled in VS but will work fine on the command line (assuming you've globally installed npm, bower, etc.) You may get some error messages in the Output window, but no build errors or warnings.

似乎没有必要关闭解决方案等。NPM 和 Bower 功能现在在 VS 中被禁用,但可以在命令行上正常工作(假设您已全局安装 npm、bower 等)。您可能会在输出窗口中收到一些错误消息,但没有构建错误或警告。

To restore normal operation, go back to External Web Tools and click "Reset to Defaults" in the lower right.
I haven't tried this with Publish -- you might have to restore defaults to successfully publish, try it if you encounter errors at that point.

要恢复正常操作,请返回外部 Web 工具并单击右下方的“重置为默认值”。
我还没有在 Publish 上试过这个——你可能需要恢复默认值才能成功发布,如果你当时遇到错误,请尝试一下。

回答by Ashlin Allen

Visual Studio 2015 Update 2 fixed this issue! Install Update 2 and you should be good to go.

Visual Studio 2015 Update 2 修复了这个问题!安装更新 2,你应该很高兴。

Direct download: http://go.microsoft.com/fwlink/?LinkId=691129
Update 2 Release Notes: https://www.visualstudio.com/news/releasenotes/vs2015-update2-vs

直接下载:http: //go.microsoft.com/fwlink/?LinkId=691129
Update 2 发行说明:https: //www.visualstudio.com/news/releasenotes/vs2015-update2-vs

Edit: "fixed" may not be entirely accurate, and it may not be entirely fixedfor all users. Maybe we can pin down what everybody's experiencing. To clarify, my experience has been as follows:

编辑:“固定”未必完全准确,它可能不完全固定于所有用户。也许我们可以确定每个人的经历。为了澄清,我的经验如下:

  • Prior to Update 2, VS would run 'npm install' everytime I opened the .sln, which was very hard to cope with.
  • After Update 2, VS runs 'npm install' in certain scenarios, which is tolerable (in my experience.)
  • 在更新 2 之前,每次打开 .sln 时,VS 都会运行“npm install” ,这很难应付。
  • 更新 2 之后,VS 在某些情况下运行“npm install”,这是可以容忍的(以我的经验)。

In my experience, post-patch VS will, upon opening the .sln, run 'npm install' if any of the dependencies in package.json are missing from the node_modules folder (or if the folder itself is missing.)

根据我的经验,如果 node_modules 文件夹中缺少 package.json 中的任何依赖项(或者如果文件夹本身丢失),则在打开 .sln 后,补丁后 VS 将运行“npm install”。

You can't disable the 'npm install', so 'fixed' may not quite be correct - however, it doesn't do it on every launch as before, so I consider it a win. Can folks confirm this is the behavior, or are we experiencing different behaviors?

你不能禁用“npm install”,所以“fixed”可能不太正确——但是,它不像以前那样在每次启动时都这样做,所以我认为这是一个胜利。人们可以确认这是行为,还是我们正在经历不同的行为?