在 Microsoft 托管的 Azure Devops Build Pipeline Agent 上安装 Visual Studio 2015 工具包 (v140)

Installing the Visual Studio 2015 toolkit (v140) on a Microsoft hosted Azure Devops Build Pipeline Agent

我有一个遗留解决方案,我们已将其移至 Azure Devops git 存储库,我正在尝试为其设置构建管道。解决方案是 v141 (2017) 和 v140 (2015) 项目的混合,只要我安装了 v140 工具集,我就可以在我的本地机器上构建 Visual Studio 2017。

理想情况下,我想使用 Microsoft 提供的代理,但 vs2017-win2016 映像似乎默认不包含 v140 工具集。由于这不是我们计划经常构建的东西,我尝试使用 2017 安装程序安装 v140 工具集:

pool:
    vmImage: 'vs2017-win2016'

steps:
- task: PowerShell@2
  displayName: 'Install Visual Studio v140 Toolset'
  inputs:
    targetType: 'inline'
    script: |
      Write-Output "Starting the installation process. This will take some time"
      $installProcess = Start-Process -FilePath $(Build.SourcesDirectory)/External/VisualStudioBuildTools/installer.exe -ArgumentList "--add Microsoft.VisualStudio.Component.VC.140", "--quiet", "--wait", "--norestart" -Wait -PassThru
      Write-Output "Install Completed with code $($process.ExitCode)"

- task: VSBuild@1
  displayName: 'Build Debug [.sln]'
  inputs:
    solution: '$(Build.SourcesDirectory)/LegacySolution.sln'
    vsVersion: '15.0'
    configuration: 'Debug'
    platform: 'x64'

当我在 Azure Devops 中 运行 执行此操作时,安装过程会在大约一分钟后以代码 0(成功)退出。但是,当它随后尝试构建解决方案时失败了:

##[error]C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Platform.targets(67,5): Error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 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".

以前有没有人试过这个好运?我唯一能想到的另一件事是尝试签入 v140 工具集的副本并尝试将其正确添加到路径中,但我可以看到这是正确的一个主要痛苦!

Installing the Visual Studio 2015 toolkit (v140) on a Microsoft hosted Azure Devops Build Pipeline Agent

一般情况下你不能。如果某事需要管理员访问权限,而您使用的是托管代理,则您不能做那件事。我已经在我的本地测试了这个命令行,我需要用管理员运行 powershell,否则,我会得到一个确认提示。

此外,MS回复:

VS has grown to a point, where installing multiple versions on the same agent is not feasible any longer for us. Also, we notice problems in side-by-side VS installations for certain project types. For these reasons, we have decided to keep a single tool set going forward. If you need multiple versions, then you would have to setup custom agents. We are sorry that we cannot meet all of our customers' requirements using a common hosted agent image.

所以,要解决这个问题,我们必须设置我们的私人代理。

希望对您有所帮助。