最近我的 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 响应文件时,构建似乎失败了。但是,这似乎是一个内部问题,而不是我的命令的问题。我不太了解内部如何dotnet build
使用msbuild
。
日志中还有一条警告和一条信息行。但是,它们不应该适用,因为我正在使用 dotnet cli 进行恢复,并且我正在UseDotNet
使用3.1.409
在global.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 开发者社区中无法使用 dotnet build 构建 fsharp 项目的问题一致。该线程包含以下相关部分,但它没有说明为什么或如何$(PathToFsc)
可能为空。
现有的错误信息准确地传达了问题;它不是 F# 特定的。.props/.targets 文件中的某些内容评估为
dotnet $(PathToFsc) some/file.rsp
,并且变量$(PathToFsc)
(或构建脚本中的任何内容)评估为空字符串。然后执行的最终命令是dotnet some/file.rsp
正常的 dotnet 行为是dotnet-<argument>
作为可执行文件查找。