首页 > 解决方案 > 詹金斯 | Node-Gyp 错误 MSB8020:找不到 v141 的构建工具(平台工具集 = 'v141')

问题描述

我是新手,正在尝试设置新的 Jenkins Build 服务器,并且正在尝试自动化节点插件 api 项目。即使我尝试在 cmd 提示符下运行 node-gyp,我也仅在 Jenkins 服务器上面临以下问题,它工作正常。

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v141 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install v141 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\jenkins_builds\Reporter-Backend\workspace\build\copy_binary.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v141 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install v141 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [C:\jenkins_builds\Reporter-Backend\workspace\node_modules\node-addon-api\src\nothing.vcxproj]
gyp ERR! build error 
gyp ERR! stack Error: `msbuild` failed with exit code: 1

Node version v10.15.3
Node-Gyp v4.0.0
Jenkins v2.164.3
Visual Studio 2019

我试图设置环境路径以及在 Gyp 文件中设置正确的 msbuild 路径。但是在 Jenkins 中,每次出现上述问题时构建都会失败。

先感谢您。

标签: node.jsjenkinsmsbuildnode-gypvisual-studio-2019

解决方案


看起来您要构建的项目来自 VS2017,其 C++ ToolSet 为 V141。

正如您提到的,您使用的是工具集为 V142 的 VS2019。

要解决这个问题:

1.我们可以将解决方案重新定位到V142 ToolSet,然后VS2019 msbuild工具构建好(在VS2019中打开.sln,右键solutionName并选择重新定位)

2.另外,您可以选择在VS2019中安装ToolSet V141。

在 VS2019 中,转到 Tools=>Get Tools and Features=> 安装 VS2017 的 C++ 构建工具:

在此处输入图像描述(假设您的项目是 X64/X86,而不是 Arm)

点击修改安装V141 Toolset,新建一个C++工程,右键Project=>properties查看是否安装成功ToolSet v141:

在此处输入图像描述

此外,您可能已经安装了 ToolSet,并且您得到的错误是由错误的 msbuild 路径或参数引起的。

因此,请确保 VS2019 的 msbuild 路径为:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe 

更新:

在 vs2019 中安装工具集后尝试设置 VCTargetsPath: VCTargetsPath= C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v150\。


推荐阅读