Search code examples
node.jsjenkinsmsbuildnode-gypvisual-studio-2019

Jenkins | Node-Gyp error MSB8020: The build tools for v141 (Platform Toolset = 'v141') cannot be found


I am new and trying to set up a new Jenkins Build server and I am trying to to automate a node addon api project. I am facing following issue only on Jenkins server even when I try to run the node-gyp on cmd prompt, it is working fine.

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

I have tried to set envirmont path as well as setting in Gyp file for correct msbuild path. But in Jenkins build is failed every time with above issue.

Thank you in Advance.


Solution

  • Looks like the project you want to build comes from VS2017 whose C++ ToolSet is V141.

    And as you mentioned you use VS2019 whose Toolset is V142.

    To fix it:

    1.We can re-target the solution to V142 ToolSet, then the VS2019 msbuild tool builds it well (Open the .sln in VS2019, right-click solutionName and choose re-target)

    2.Also, you can choose to install the ToolSet V141 in VS2019.

    In VS2019, go Tools=>Get Tools and Features=> Install the C++ build tools for VS2017:

    enter image description here (Assuming your project are in X64/X86, not Arm)

    Click modify to install the V141 Toolset, and create a new C++ project, Right-click Project=>properties to check if we install ToolSet v141 successfully:

    enter image description here

    Also, there is possibility that you've installed the ToolSet, and the error you gets result from the wrong msbuild path or parameter.

    So make sure the msbuild path for VS2019 is:

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

    Update:

    Try settinging VCTargetsPath: VCTargetsPath= C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v150\ after installing the toolset in vs2019.