How to install (v142) Build tools in Visual studio

151,872

Solution 1

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

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 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. MSbuild Error: The builds tools for v140 (Platform Toolset = 'v140') cannot be found

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

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

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

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)

Share:
151,872
Vardaan Shukla
Author by

Vardaan Shukla

Love to work on Ubuntu.

Updated on February 20, 2022

Comments

  • Vardaan Shukla
    Vardaan Shukla about 2 years

    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".
    
  • Richard Chambers
    Richard Chambers over 4 years
    Your proposed answer will work fine should the OP being using VS 2019 however in a comment the OP says they are using VS 2017. Another comment suggests upgrading from VS2017 to VS2019. It appears your post does not actually answer the question asked.
  • Martin Verjans
    Martin Verjans over 4 years
    @RichardChambers actually this post does answer the question, as build tools v142 means the original project comes from VS2019. And the problem is to open this project using VS2017. Had the same issue and this solution worked.
  • Richard Chambers
    Richard Chambers over 4 years
    @MartinVerjans if a project for VS2019 needs VS2019 and you are on VS2017 and you upgrade to VS2019, then of course this posted answer would work. However if you are on VS2017 and must remain on VS2017 for some reason and an upgrade is not feasible then it doesn't work since you can't upgrade.
  • Thomas
    Thomas about 4 years
    This answer solves the problem. If you are on VS2017 you can downgrade the platform tools used to V141 (or even earlier), worked for me without problem. Installing a newer VS is not necessary unless specific features of the newer build tools are required by the project (rare).
  • winux
    winux almost 4 years
    Apologies for my rant but let me know if I'm missing a lot. This explanation just made me realize how unorganized the architecture of visual studio products are. If they planned to allow multiple versions of Visual Studio that will be independent to each other, they could have organized a Visual Studio Manager or something that automatically organizes which configuration settings will be used by each installed VS. Should be able to use old VS and back to new VS without a problem. It's just disappointing how can a big company miss this.