御成門プログラマーの技術日記

Microsoft AzureやAngularなどの技術情報を発信します

Azure DevOps のPipelines内のdotnet publishのエラーと解決方法

Azure DevOps の Pipelines の中でdotnet publish している部分がエラーになっていたので解決方法を情報共有。

##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
##[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
##[error]Dotnet command failed with non-zero exit code on the following projects : [ 'D:\\a\\1\\s\\(myPath)\\(myProjectName).csproj' ]

バージョン関係のエラーが出ていそうですが、.NET 5 は使っておらず、.NET6(現在はまだサポート期間内)を使用しているので理由はわからないのですが、yaml内でDotNet Publish する前にバージョンを指定してあげたらエラーが回避できた。

  - task: UseDotNet@2
    displayName: Use .NET
    inputs:
      version: 6.x

同じバージョンで同じような構成のコードがある他のプロジェクトでは発生していなかったので、Azure DevOps Pipelines の内部のエージェント的な関係かなと思います。