所有Visual Studio安装程序崩溃,可视化构建工具也无法正常工作

All visual studio installers crash and visual build tools won't work either

本文关键字:常工作 工作 工具 安装 Studio Visual 程序 崩溃 构建 可视化 所有      更新时间:2023-10-16

如果nodejs,特别是node-gyp不依赖于Visual Studio,我就根本不会在Visual Studio上乱搞了。我真正想做的就是安装active-win npm包,但因为它有一个窗口API依赖项,我需要运行node-gyp,这让我陷入了困境。

不管出于什么原因,2015年visualstudio安装程序崩溃了,但我只是使用了npm install --global --production windows-build-tools。它成功地安装了构建工具,但是这里的问题仍然存在。

这也是一个较小的错误,节点gyp试图查找/v120/,尽管msmversion设置为2015,但我通过设置VCTargetsPath位置解决了这个问题。

以下是运行npm i-D活动胜利的完整错误:

C:UsersHenry HuntDocumentsGitRepludite>npm install -D active-win
> iconv@2.3.5 install C:UsersHenry HuntDocumentsGitRepluditenode_modulesiconv
> node-gyp rebuild

C:UsersHenry HuntDocumentsGitRepluditenode_modulesiconv>if not defined npm_config_node_gyp (node "N:Nodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-bin\....node_modulesnode-gypbinnode-gyp.js" rebuild )  else (node "N:Nodejsnode_modulesnpmnode_modulesnode-gypbinnode-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:UsersHenry HuntDocumentsGitRepluditenode_modulesiconvbuildiconv.vcxproj(20,3): error MSB4019: The imported p
roject "C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.Cpp.Default.props" was not found. Confirm that
the path in the <Import> declaration is correct, and that the file exists on disk.
gyp ERR! build error
gyp ERR! stack Error: `C:Program Files (x86)MSBuild14.0binMSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (N:Nodejsnode_modulesnpmnode_modulesnode-gyplibbuild.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "N:\Nodejs\node.exe" "N:\Nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:UsersHenry HuntDocumentsGitRepluditenode_modulesiconv
gyp ERR! node -v v12.13.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
> ref-napi@1.4.2 install C:UsersHenry HuntDocumentsGitRepluditenode_modulesref-napi
> node-gyp rebuild

C:UsersHenry HuntDocumentsGitRepluditenode_modulesref-napi>if not defined npm_config_node_gyp (node "N:Nodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-bin\....node_modulesnode-gypbinnode-gyp.js" rebuild )  else (node "N:Nodejsnode_modulesnpmnode_modulesnode-gypbinnode-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:UsersHenry HuntDocumentsGitRepluditenode_modulesref-napinode_modulesnode-addon-apisrcnothing.vcxproj(20,3)
: error MSB4019: The imported project "C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V140Microsoft.Cpp.Default.pro
ps" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
gyp ERR! build error
gyp ERR! stack Error: `C:Program Files (x86)MSBuild14.0binMSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (N:Nodejsnode_modulesnpmnode_modulesnode-gyplibbuild.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "N:\Nodejs\node.exe" "N:\Nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:UsersHenry HuntDocumentsGitRepluditenode_modulesref-napi
gyp ERR! node -v v12.13.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm WARN @date-io/date-fns@1.3.11 requires a peer of date-fns@2.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN extract-text-webpack-plugin@3.0.2 requires a peer of webpack@^3.1.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: iconv@2.3.5 (node_modulesiconv):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: iconv@2.3.5 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: ref-napi@1.4.2 (node_modulesref-napi):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: ref-napi@1.4.2 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
+ active-win@6.0.0
added 2 packages from 3 contributors, updated 1 package and audited 10413 packages in 6.338s
found 0 vulnerabilities

安装的构建工具版本是2015,其输入的文件夹\V140\实际上是存储配置的地方。缺少的一个文件是Microsoft.Cpp.Default.props。我找不到有同样问题的人。有很多人都有同样的错误,但在解决他们的问题时,Microsoft.Cpp.Default.props只是在其他目录中。这是它应该在的目录,但它不在那里。

我该如何解决这个问题?

首先,我下载了Visual Studio 2019,而不是使用node_build_tools。尽管节点生成工具声称已经安装了实际的C:\Program Files(x86(/MBuild,但其中没有任何所需的文件npm。在我完全卸载了以前的Visual Studio安装程序后,2019年的安装程序运行良好。

好吧,在那之后就变得很容易了。以下是您需要做的:

  • npm config set msvs_version 2019
  • npm config set msbuild_path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"
  • 然后设置VCTargetsPath本地环境变量,不可以。您不能简单地在npm配置或注册表中设置它。我试过了。
    1. CMD
      • SET VCTargetsPath=C:Program Files (x86)Microsoft Visual Studio2019CommunityMSBuildMicrosoftVCv160
      • (不要忘记最后一个反斜杠,如果你忘记了,它就不会起作用(
    2. GitBash或其他类似bash的shell
      • VCTargetsPath="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\"

注意:虽然Visual Studio允许您选择安装Visual Studio IDE文件夹的位置,它只是IDE将文件保存到计算机上任何路径或驱动器的默认位置,但上面的实际Microsoft Visual Studio文件夹始终安装到C:\Program files(x86(\Microsoft Visual Studio\,因此不要更改它。