如果更改我的 Azure DevOps 代理,为什么我的 MSbuild 命令路径无法访问?

Why is my MSbuild command path not reachable if I change my Azure DevOps agent?

当我从 "Hosted" Agent 更改为“Hosted VS2017”时,我的 Azure DevOps 构建任务无法找到我的解决方案路径。

文件夹组织是否从一个代理更改为另一个?

我的 C# 解决方案用于 运行 .NET Framework 4.6,我现在参考 4.7.1 版本。这就是为什么我显然需要使用 "Hosted VS2017" 代理而不是默认的 "Hosted" 代理。 但是在尝试构建我的解决方案时,使用 gulpfile 的任务失败了。我试图通过诊断执行构建,但在我的第一个 MSbuild 命令中,我得到的信息不多于“系统找不到指定的路径。”。

---

[command]C:\npm\prefix\gulp.cmd CI-default --gulpfile D:\a\s\source\back-end\gulpfile.js
[‌15:41:53‌] Using gulpfile D:\a\s\source\back-end\gulpfile.js‌
[‌15:41:53‌] Starting 'CI-default'...‌
[‌15:41:53‌] Starting 'Publish-All-Projects'...‌
[‌15:41:53‌] Starting 'Build-Solution'...‌
[‌15:41:53‌] Using automatic maxcpucount‌
The system cannot find the path specified.
[‌15:41:53‌] { Error: Command failed: "C:\Program Files (x86)\MSBuild.0\Bin\MSBuild.exe" "D:\a\s\source\back-end\******.sln" "/target:Build" /verbosity:minimal /toolsversion:14.0 /nologo /maxcpucount /property:Configuration="Release"‌
The system cannot find the path specified.

 at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:189:13)
    at maybeClose (internal/child_process.js:970:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
  killed: false,
  code: 1,
  signal: null,
  cmd:
   '"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "D:\a\1\s\source\back-end\ALE.sln" "/target:Build" /verbosity:minimal /toolsversion:14.0 /nologo /maxcpucount /property:Configuration="Release"' }


---

构建在此步骤失败但应该正确执行(当我使用默认 "Hosted" 代理或在我的本地计算机上使用 Visual Studio 时它确实执行)

Why is my MSbuild command path not reachable if I change my Azure DevOps agent?

因为 Visual Studio 2015 默认安装在“Hosted”代理上,而 Hosted VS2017 带有 Visual Studio 默认为2017.

但是,MSBuild 14.015.0 的路径不同。

MSBuild 14.0 的默认路径是 C:\Program Files (x86)\MSBuild.0\Bin\MSBuild.exe

但是 MSBuild 15.0 的默认路径是 C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.0\Bin\MSBuild.exe.

因此,要解决此问题,您应该更改 CMD 脚本中的 MSBuild:

 cmd:
   '"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"

 cmd:
   C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe

希望对您有所帮助。