为什么在指定特定版本时 vswhere 找不到 VS Build Tools?

Why does vswhere not find VS Build Tools when a specific version is specified?

在我们的构建任务日志中,我看到,

"D:\DevopsBuildAgents\Agent 1\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [16.0,17.0) -latest -format json
"D:\DevopsBuildAgents\Agent 1\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [16.0,17.0) -products Microsoft.VisualStudio.Product.BuildTools -latest -format json
"D:\DevopsBuildAgents\Agent 1\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [15.0,16.0) -latest -format json
"D:\DevopsBuildAgents\Agent 1\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [15.0,16.0) -products Microsoft.VisualStudio.Product.BuildTools -latest -format json
##[warning]Visual Studio was not found. Try installing a supported version of Visual Studio. See the task definition for a list of supported versions.
##[warning]Unable to find MSBuild version '14.0' for architecture 'x86'. Falling back to version '4.0'.

如果我 运行 这个命令:

,这是我看到的输出
"D:\DevopsBuildAgents\Agent 1\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -version [16.0,17.0) -products Microsoft.VisualStudio.Product.BuildTools -latest -format json    
[]

如果删除版本参数,这是我看到的输出:

"D:\DevopsBuildAgents\Agent 1\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -latest -format json
[
  {
    "instanceId": "07f7c44a",
    "installDate": "2022-05-07T03:42:53Z",
    "installationName": "VisualStudio/17.1.6+32421.90",
    "installationPath": "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools",
    "installationVersion": "17.1.32421.90",
    "displayName": "Visual Studio Build Tools 2022",
    "description": "The Visual Studio Build Tools allows you to build native and managed MSBuild-based applications without requiring the Visual Studio IDE. There are options to install the Visual C++ compilers and libraries, MFC, ATL, and C++/CLI support.",
    "updateDate": "2022-05-07T03:42:53.2726915Z",
    "enginePath": "C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service",
    "channelId": "VisualStudio.17.Release",
    "channelUri": "https://aka.ms/vs/17/release/channel",
    "installedChannelUri": "https://aka.ms/vs/17/release/channel",
    "releaseNotes": "https://docs.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.1#17.1.6",
    "thirdPartyNotices": "https://go.microsoft.com/fwlink/?LinkId=661288"
  }
]

如果我只是 运行:

,这是我得到的输出
"D:\DevopsBuildAgents\Agent 1\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.166.2\ps_modules\MSBuildHelpers\vswhere.exe"
Visual Studio Locator version 1.0.62 [query version 3.1.2200.53929]
Copyright (C) Microsoft Corporation. All rights reserved.

我尝试修复安装 Visual Studio 2022 Build Tools。

似乎存在版本 17.x 的构建工具。为什么在将版本参数添加到此命令时它没有返回任何内容,如代理日志中所示?

事实证明,最新版本的 Azure Devops 2020.1.1 仍然不支持 Visual Studio 2022。因此,即使较新的 devops 代理可以识别该软件,但 Devops 服务器无法正确查询它.

如果它正常工作,它会发出一个看起来像 -version [17.0,18.0) 或类似的版本参数。

卸载 Visual Studio 2022 构建工具并将其替换为 Visual Studio 2019 构建工具,解决了问题。

或者,我找到了至少两个解决方案来替换 Azure Devops 2020 中的内置任务并启用对 Visual Studio 2022 的支持。

https://github.com/jessehouwing/azure-pipelines-tasks-zips/releases/tag/m204

https://www.almhussar.com/2021/12/25/how-to-build-and-support-net-6-and-vs-2022-projects-using-azure-devops-server-2020/