【问题标题】:Azure Pipeline fails on `dotnet build` with error "command or file was not found"Azure Pipeline 在 `dotnet build` 上失败,并出现错误“找不到命令或文件”
【发布时间】:2021-06-07 09:59:54
【问题描述】:

最近我的 Azure Pipeline 构建开始失败,而我的构建脚本/yaml 没有任何更改。错误如下,但它们仍然很清楚细节。

C:\hostedtoolcache\windows\dotnet\sdk\3.1.406\FSharp\Microsoft.FSharp.Targets(279,9): error MSB6006: "dotnet.exe" exited with code 1. [D:\a\1\s\src\App.Core\App.Core.fsproj]

##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1

为了获得更多信息,我还在构建步骤中添加了--verbosity detailed,其中显示了以下详细信息。

Could not execute because the specified command or file was not found.
Possible reasons for this include:
    * You misspelled a built-in dotnet command.
    * You intended to execute a .NET Core program, but dotnet-@C:\Users\VssAdministrator\AppData\Local\Temp\tmp3147e93b44f0436c9449d0f384ba6079.rsp does not exist.
    * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

因此,在尝试使用 msbuild response file 时构建似乎失败了。但是,这似乎是一个内部问题,而不是我的命令的问题。我不太了解dotnet build 在内部如何使用msbuild

日志中还有一条警告和一条信息行。但是,它们不应该适用,因为我正在使用 dotnet cli 进行恢复,并且我正在使用 UseDotNet 安装 SDK 版本 3.1.409global.json 中的相同版本

##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting

global.json 文件的内容:

{
  "sdk": {
    "version": "3.1.409",
    "rollForward": "latestFeature"
  }
}

在构建管道中,包在构建之前的单独步骤中恢复。还有一个项目 (dbup) 在完整构建 (dotnet build) 成功之前构建。虽然完整的构建步骤失败。我已经包含了azure-pipelines.yml文件中的相关步骤。

    steps:
      - task: UseDotNet@2
        displayName: 'Use .Net Core sdk 3.1.409'
        inputs:
          version: 3.1.409

      - task: DotNetCoreCLI@2
        displayName: 'dotnet restore'
        inputs:
          command: restore
          projects: App.sln

      - task: DotNetCoreCLI@2
        displayName: 'dotnet build dbup'
        inputs:
          command: build
          projects: 'src\App.DatabaseUp\App.DatabaseUp.fsproj'
          arguments: '--no-restore --configuration release --version-suffix $(Build.BuildNumber)'

      - task: DotNetCoreCLI@2
        displayName: 'dotnet build'
        inputs:
          command: build
          projects: App.sln
          arguments: '--no-restore --configuration release --version-suffix $(Build.BuildNumber)'

到目前为止,我已尝试使用不同的 SDK 版本(3.1.406 和 3.1.409),并检查了警告和信息消息中的所有建议。还值得注意的是,该项目确实在本地使用dotnet build 成功构建。解决方案中的所有项目目标netcoreapp3.1

我认为问题是由于我使用 vmImage: 'windows-latest' 时图像更新造成的,但是我看不到任何问题,而且我已经没有想法了。


更新

Microsoft.FSharp.Targets(279,9) 中的文件和行号似乎表明这是调用 FSharp 编译器的问题。

这也与 vs 开发者社区 unable to build fsharp project using dotnet build 中的问题一致。该线程包含以下相关部分,但它没有说明$(PathToFsc) 为何或如何为空。

现有的错误信息准确地传达了问题;它不是 F# 特定的。 .props/.targets 文件中的某些内容评估为dotnet $(PathToFsc) some/file.rsp,而变量$(PathToFsc)(或构建脚本中的任何内容)评估为空字符串。然后执行的最终命令是 dotnet some/file.rsp,正常的 dotnet 行为是查找 dotnet-&lt;argument&gt; 作为可执行文件。

【问题讨论】:

  • 不是一个答案,但我想知道它是否与此有关:stackoverflow.com/questions/67800998/… - 似乎事情可能在 VS 16.9 和 16.10 之间发生了变化。
  • @Charles Mager 就是这样!

标签: .net f# azure-pipelines dotnet-sdk


【解决方案1】:

问题实际上是由于 FscToolPath 评估为空字符串。

现有的错误信息准确地传达了问题;它不是 F# 特定的。 .props/.targets 文件中的某些内容评估为 dotnet $(PathToFsc) some/file.rsp 并且变量 $(PathToFsc) (或构建脚本中的任何内容)评估为空字符串。然后执行的最后一个命令是 dotnet some/file.rsp,正常的 dotnet 行为是查找 dotnet- 作为可执行文件。

第二个因素是,FSC 的位置确实由于 VM 映像上的 Visual Studio 更新而发生了变化。

不是答案,但我想知道它是否与此有关:stackoverflow.com/questions/67800998/... - 似乎事情可能在 VS 16.9 和 16.10 之间发生了变化。

最后,它影响我的原因是因为我手动设置了 FscCompilerPath,因为 TypeProvider 由于依赖于 System.Data.SqlClient 而不支持 dotnet 核心管道。

<DisableAutoSetFscCompilerPath>true</DisableAutoSetFscCompilerPath>
<PropertyGroup Condition="'$(IsWindows)' == 'true' AND Exists('C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\FSharp\fsc.exe')">
  <FscToolPath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\FSharp</FscToolPath>
  <FscToolExe>fsc.exe</FscToolExe>
</PropertyGroup>

因此将FscToolPath 更新为C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools 解决了该问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    • 2018-12-17
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多