How to install (v142) Build tools in Visual studio

C++Visual StudioVisual Studio-2017

C++ Problem Overview


As I am trying to build something in visual studio then visual studio show me some warning and then If i ignored it and build then error occurs.

    error MSB8020: The build tools for v142 (Platform Toolset = 'v142') 
    cannot be found. To build using the v142 build tools, please install 
    v142 build tools.

It will also show me an Alternate option I also tried it but not works.

    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++ Solutions


Solution 1 - C++

I had the same problem, but when trying to open a project made in VS2019 with VS2017, so I changed this in my project:

Go to: Project->Properties->General->Platform Toolset and change to the current version of your VS.

Solution 2 - C++

The bottom line is that you need to install Visual Studio 2019 to access the v142 tools.

Along with different versions of Visual Studio (VS2015, VS2017, VS2019), Microsoft also releases different build tool versions as they continue to improve the compiler and provide additional capabilities and to meet updated language standards (C++, C++11, C++17, etc.). See https://stackoverflow.com/questions/44046355/visual-studio-2015-not-detecting-v141-2017-build-tools

See as well this Microsoft blog posting about build tools for VS2017 and accessing the older v140 from VS2015, Visual Studio Build Tools now include the VS2017 and VS2015 MSVC Toolsets.

> Many of you have told us that you still need the MSVC v140 toolset > from Visual Studio 2015 to continue building older codebases. We’ve > updated the Visual Studio Build Tools to include the v140 toolset from > Visual Studio 2015 Update 3 including the most recent servicing > release. You might notice that the compiler toolset build version may > not match the version in a full VS 2015 install, even though they are > the same compilers. That happens because we build the full Visual > Studio and the Visual Studio Build Tools in separate branches that may > be built on different days. > > The Visual C++ build tools workload in the Visual Studio Build Tools > will install the latest v141 toolset from VS2017 by default. The v140 > toolset from VS2015 will install side-by-side with the v141 toolset. > To install them just select the “VC++ 2015.3 v140 toolset for desktop > (x86,x64)” at the bottom of the “Optional” section.

In your case, V142 build tools was released with VS2019. It does not appear that v142 is available for VS2017. The most recent build tools for VS2017 looks to be v141.

You can use the Visual Studio installer to modify the build tools available by adding or removing from the list. This SO posting describes a similar problem but with v140 missing in a VS2015 Visual Studio installation. https://stackoverflow.com/questions/33154696/msbuild-error-the-builds-tools-for-v140-platform-toolset-v140-cannot-be-f

However if Microsoft has not released a particular Build Tools version for the Visual Studio you are using then it will not show in the list of available toolsets.

It looks like beginning with VS2015, Microsoft is providing a standard Visual Studio engine that is shared among VS 2015, VS2017, and VS2019 with build tools and various components being updated to provide new features and functionality and new language standards compliance. There are dependencies between the Visual Studio version and what build tools and components can be used with the Visual Studio version, e.g. v142 is not available for VS2017, most probably to provide an incentive for purchasing the newer product.

On installing VS2017 after installing VS2019

As a side note, while doing a bit of discovery on this question, I have found some articles that indicate that if you have a recent Visual Studio installed and then install an earlier version of Visual Studio, the default target build tools can also change to the build tools for the earlier install.

In other words, if you have VS2019 with a default target of v142 already installed and then install VS2017, the default target will change to v141 requiring you to actually set the build target to v142 when using VS2019.

Solution 3 - C++

I had the same problem but I wanted to keep both Visual Studio 2017, Visual Studio 2019 and Visual Studio 2022 support for building the same project.

What I did is edited my .vcxproj, which is an MSBuild-format file, like this:

Before (toolset 1.42, only available with Visual Studio 2019, fails with Visual Studio 2017 and 2022):

...
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    ...
    <PlatformToolset>v142</PlatformToolset>
    ...
  </PropertyGroup>
...

After, each Visual Studio Version uses its own toolset version:

...
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    ...
	<PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset>
	<PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset>
	<PlatformToolset Condition="'$(VisualStudioVersion)' == '17.0'">v143</PlatformToolset>
    ...
  </PropertyGroup>
...

Solution 4 - C++

I'm using both Visual studio 2017 and visual studio 2019 on two different computers and regularly have problems with the platform toolset.

On VS 2019, when opening a solution/project created with VS2017, i usually simply go to "projects" in the menu bar on the top and choose "retarget solution" (this probably sets the platform to V142).

on the contrary, on VS 2017, when opening the solution/project created with VS2019 (platform toolset v142),to allow it to work, I need to "downgrade" it to the platform v141. To do that, I right clic on the project (not the solution) and choose properties, then "general" and look for "platform toolset" that i set to "Visual studio 2017 (v141)" and then i can compile again without errors.

the property panel to set the correct platform toolset

Solution 5 - C++

Open Visual Studio, I'm using (Version 17.1.0). Download the required file and install it.

Go to Tools>Get tools and features

Go to Installation details>Desktop Development with c++ (for windows)

Solution 6 - C++

This worked for me: Go into the ProjectName.vcxproj file and remove the v142 build script and replace with the build script that corresponds to the Microsoft Visual Studio version you are using or remove the script and Retarget your project if it is an upgraded MVSC.

Solution 7 - C++

After installing the latest upgrade of VS2019, I had exactly the same problem as the original poster i.e. error MSB8020 re: building apps in VS2017. I used the simplest app in the series that were not building (all with the error above), and used 'Retarget solution', selecting Windows SDK version 10.0.17763.0. After that I did a rebuild and the app built fine. I checked the properties for each project in the solution, and the Windows SDK version had changed to 10.0.17763.0 as you would expect.

When I then opened other VS2017 apps, they all built fine too without making any changes (these apps all failed before). However, their project properties still refer an SDK version 10.0.14393.0 which presumably is the VS2019 one. All the apps now 'magically' show their toolset as Visual Studio 2017 (v141). HTH, even if not explaining why it works.

Solution 8 - C++

I had a similar problem. I had a trial version of VS2019 Professional. I worked on some projects using this but later I had to downgrade to VS2017 Professional (which I had a license for). So in my project, I did retarget the project to reflect the new version (Project -> Retarget solution) and selected Windows SDK Version 10.0.17763.0 (in my case). After this I went to (Project -> Properties) and in (Configuration Properties -> General -> Platform Toolset) I changed to Visual Studio 2017 (v141). This should have solved the issue but at build time I got the error "error MSB8020: The build tools for v142 (Platform Toolset = 'v142') cannot be found.". To solve this I had to open the .vcxproj in notepad++.

<PropertyGroup Label="Configuration">
<OutDir>../bin/</OutDir>
<ConfigurationType>Utility</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v142</PlatformToolset>

I changed the last line in this code block to v141. Seems changing project properties does not change the .vcxproj file automatically. After this my project built with no errors.

Solution 9 - C++

also I faced the same problem. I run C++ code in VS 2019. I tried some different ways but couldn't solve. Finally I found article that helped me then my code worked: this article helpful

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVardaan ShuklaView Question on Stackoverflow
Solution 1 - C++AndaView Answer on Stackoverflow
Solution 2 - C++Richard ChambersView Answer on Stackoverflow
Solution 3 - C++Simon MourierView Answer on Stackoverflow
Solution 4 - C++Via_fx_24View Answer on Stackoverflow
Solution 5 - C++Atish PaulView Answer on Stackoverflow
Solution 6 - C++NisunView Answer on Stackoverflow
Solution 7 - C++Joao G. FerreiraView Answer on Stackoverflow
Solution 8 - C++OmiView Answer on Stackoverflow
Solution 9 - C++Yusif KarimovView Answer on Stackoverflow