C++ 如何在 Visual Studio 中安装 (v142) 构建工具

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/56901371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 16:07:04  来源:igfitidea点击:

How to install (v142) Build tools in Visual studio

c++visual-studiovisual-studio-2017

提问by Danraptor

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.

当我尝试在 Visual Studio 中构建某些东西时,visual studio 会向我显示一些警告,然后如果我忽略它并构建,则会发生错误。

    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".

回答by Richard Chambers

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

最重要的是,您需要安装 Visual Studio 2019 才能访问 v142 工具。

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

随着 Visual Studio 的不同版本(VS2015、VS2017、VS2019),Microsoft 还发布了不同的构建工具版本,因为它们不断改进编译器并提供附加功能并满足更新的语言标准(C++、C++11、C++ 17 等)。请参阅Visual Studio 2015 未检测到 v141 (2017) 构建工具

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.

另请参阅这篇关于 VS2017 构建工具和从 VS2015 访问旧版 v140 的 Microsoft 博客文章,Visual Studio 构建工具现在包括 VS2017 和 VS2015 MSVC 工具集

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.

你们中的许多人告诉我们,您仍然需要 Visual Studio 2015 的 MSVC v140 工具集来继续构建旧代码库。我们已更新 Visual Studio 构建工具以包含来自 Visual Studio 2015 更新 3 的 v140 工具集,包括最新的服务版本。您可能会注意到编译器工具集构建版本可能与完整 VS 2015 安装中的版本不匹配,即使它们是相同的编译器。发生这种情况是因为我们在可能在不同日期构建的不同分支中构建完整的 Visual Studio 和 Visual Studio 构建工具。

默认情况下,Visual Studio 构建工具中的 Visual C++ 构建工具工作负载将安装来自 VS2017 的最新 v141 工具集。VS2015 的 v140 工具集将与 v141 工具集并行安装。要安装它们,只需选择“可选”部分底部的“VC++ 2015.3 v140 桌面工具集 (x86,x64)”。

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.

就您而言,V142 构建工具是随 VS2019 一起发布的。v142 似乎不适用于 VS2017。VS2017 的最新构建工具看起来是 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

您可以使用 Visual Studio 安装程序通过在列表中添加或删除来修改可用的构建工具。这个 SO 帖子描述了一个类似的问题,但在 VS2015 Visual Studio 安装中缺少 v140。MSbuild 错误:找不到 v140(平台工具集 = 'v140')的构建工具

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.

但是,如果 Microsoft 尚未为您正在使用的 Visual Studio 发布特定的构建工具版本,则它不会显示在可用工具集列表中。

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.

作为旁注,在对这个问题进行一些发现时,我发现一些文章表明,如果您最近安装了 Visual Studio,然后安装了早期版本的 Visual Studio,则默认目标构建工具也可以更改为早期安装的构建工具。

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.

换句话说,如果你已经安装了默认目标为 v142 的 VS2019,然后再安装 VS2017,那么默认目标将变为 v141,需要你在使用 VS2019 时实际将构建目标设置为 v142。

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.

看起来从 VS2015 开始,Microsoft 提供了一个在 VS 2015、VS2017 和 VS2019 之间共享的标准 Visual Studio 引擎,其中构建工具和各种组件正在更新,以提供新的特性和功能以及新的语言标准合规性。Visual Studio 版本与 Visual Studio 版本可以使用哪些构建工具和组件之间存在依赖关系,例如 v142 不适用于 VS2017,这很可能是为了鼓励购买较新的产品。

回答by Anda

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

我遇到了同样的问题,但是当尝试使用 VS2017 打开在 VS2019 中制作的项目时,我在我的项目中进行了更改:

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

转到:Project->Properties->General->Platform Toolset 并更改为 VS 的当前版本。

This worked for me!

这对我有用!

回答by Per Feldvoss Olsen

Thanks - this depends on how your going forward with your project. The project file is, apparently built with v142, this is however not NECESSARILY a must. So you can simply use the above solution and use the 'build tool' version that you have. Likewise there may be other VS versions that can be used - I overcame this and the project built without any apparent problems.

谢谢 - 这取决于你如何推进你的项目。项目文件显然是用 v142 构建的,但这不是必须的。因此,您可以简单地使用上述解决方案并使用您拥有的“构建工具”版本。同样,可能还有其他 VS 版本可以使用 - 我克服了这个问题,并且构建的项目没有任何明显的问题。

I guess this will happen often when you get a project from a professional developer, and you want to build it using the free VS version!

我想当您从专业开发人员那里获得一个项目并且您想使用免费的 VS 版本构建它时,这种情况会经常发生!

回答by Simon Mourier

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

我遇到了同样的问题,但我想保留 Visual Studio 2017 和 Visual Studio 2019 对构建同一个项目的支持。

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

我所做的是编辑 my .vcxproj,这是一个 MSBuild 格式的文件,如下所示:

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

之前(工具集 1.42,仅适用于 Visual Studio 2019,在 Visual Studio 2017 中失败):

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

After, Visual Studio Version for 2017 is '15.0' and toolset is 1.41:

之后,2017 年的 Visual Studio 版本为“15.0”,工具集为 1.41:

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