首页 > 解决方案 > 通过 2019 构建工具安装时未检测到 MSVC2015

问题描述

我正在尝试为 VS2015 C++ 构建创建一个 windows docker 容器。我找到了一些文档如何在容器中安装构建工具,它适用于 VS2017。

但是,在尝试设置 2015 版本时,MSBuild.exe 抱怨它找不到 v140 并且尽管添加--add Microsoft.VisualStudio.Component.VC.v140vs_buildtools.exe调用。我也无法在任何子文件夹中找到任何 v140 cl.exe

显然,像这样的基于 GUI 的解决方案不是一种选择。

这是我更改的 Dockerfile:

# escape=`

# Use the latest Windows Server Core image with .NET Framework 4.8.
FROM mcr.microsoft.com/windows/servercore:1903

# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]
ARG BUILD_TOOLS_VERSION=16

# Download the Build Tools bootstrapper.
ADD https://aka.ms/vs/${BUILD_TOOLS_VERSION}/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe

RUN C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache `
    --installPath C:\BuildTools `
    --add Microsoft.VisualStudio.Workload.VCTools `
    --add Microsoft.VisualStudio.Component.VC.CLI.Support `
    --add Microsoft.VisualStudio.Component.VC.v140 `
    --add Microsoft.VisualStudio.Component.Windows10SDK.18362 `
    --add Microsoft.VisualStudio.Component.VC.CMake.Project `
 || IF "%ERRORLEVEL%"=="3010" EXIT 0

# put MSBuild.exe on PATH
RUN setx path "%path%;C:\BuildTools\MSBuild\Current\Bin"

# Define the entry point for the docker container.
# This entry point starts the developer command prompt and launches the PowerShell shell.
ENTRYPOINT ["C:\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]

标签: visual-studiodockermsbuild

解决方案


通过 2019 构建工具安装时未检测到 MSVC2015

Build Tool for VS2019 目前可以安装v140 build tool for VS2015

在此处输入图像描述

主要问题是您为 v140 构建工具使用了错误的组件 ID。

正如本文档所说,您应该使用

Microsoft.VisualStudio.Component.VC.140.

解决方案

用这个:

--add Microsoft.VisualStudio.Component.VC.140而不是--add Microsoft.VisualStudio.Component.VC.v140.


推荐阅读