Azure Pipelines: "Dotnet command failed with non-zero exit code on the following projects"
The .NET Core task (DotNetCoreCLI@2) runs dotnet once for each project file its pattern matches. When one run exits with a code other than 0, the task logs it, goes on with the next project, and at the end lists every project that failed in this message (the task's source). So the message only says which projects failed. Why they failed is in dotnet's own output above it (questions on Stack Overflow with this message have been seen over 320,000 times).
When the failing step is part of a pull request's build validation, the pull request waits on it: Azure DevOps Pull Requests, a plugin for JetBrains IDEs, lists the pull request's branch policies with their state in Rider, and with Pro runs a failed build policy again once the fix is pushed. Get it on JetBrains Marketplace
What it looks like
##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1(on Windows,'C:\Program Files\dotnet\dotnet.exe') for each failed run, then##[error]Dotnet command failed with non-zero exit code on the following projects : /home/vsts/work/1/s/src/Web/Web.csproj.- Before it, a warning says that .NET 5 has issues with NuGet 5.7 or older. The task prints it for every failure of build, publish, run and test, so it is the cause only if an old NuGet task did your restore.
Find the real error
- Open the step's log and look above the message for lines with
errorand a code:CSfrom the compiler,MSBfrom MSBuild,NETSDKfrom the .NET SDK,NUfrom NuGet. The first one is usually the one to fix; the rest often follow from it. - If the log is long, download it from the run's menu and search it there. Running the same
dotnetcommand on your machine with the same SDK version shows the same error.
A project you did not mean to build
- A pattern such as
**/*.csprojmatches every project file in the repository, also old, sample or broken projects that are not in your solution. On the most read question, the accepted answer was exactly this: the project in the message was not in the solution. - Point
projects:at the solution,Fabrikam.sln, or at a narrower pattern, such assrc/**/*.csproj.
The SDK on the agent
NETSDK1045: The current .NET SDK does not support targeting .NET 9.0means the agent's SDK is older than theTargetFrameworkof the project (Microsoft's page on NETSDK1045).- Add
- task: UseDotNet@2withpackageType: sdkandversion: 9.0.xbefore the .NET Core task. With aglobal.json, useuseGlobalJson: trueinstead, and the task installs the SDK the file asks for (the task's reference).
The restore inside build, test and publish
- Build, test and publish restore packages on their own first. Against an authenticated feed, that restore fails even after a restore step that worked, because the restore step removed the credentials it used. Microsoft's answer is to add
--no-restoretoarguments(the task's reference). The test command also ignoresfeedRestoreandvstsFeed, so restore in its own step. - For NuGet errors in the restore, see Unable to load the service index for source (NU1301).
NU1101: Unable to find packagemeans no source the restore used has the package: the feed lacks it, or its upstream source is off. - With
--no-restore, the restore has to match the later command. A publish with-r linux-x64after a restore without it fails withNETSDK1047, that the assets file has no target for that runtime. Give the restore the same-r.
Tests that failed
dotnet testexits with 1 when a test fails, and the task then names the test project in this message. WithpublishTestResultson, the default, the task publishes the test results before it fails, so the run's Tests tab shows which tests failed and why.
Azure DevOps pull requests in IntelliJ IDEA and Rider
Azure DevOps Pull Requests, a plugin by Lesstep for JetBrains IDEs 2024.1 or later and Android Studio, reads the organization, project and repository from your git remote and lists the pull requests that wait for your review in an IDE tool window, on Azure DevOps Services and on Azure DevOps Server. It shows the branch policies of a pull request with their state, so a required build that has not passed is next to its pull request, and with Pro you run a failed or expired build policy again from there. The review inbox is free; voting, commenting, completing and creating are Pro, with a 30-day trial.
Get it on JetBrains Marketplace
Azure DevOps, Azure Pipelines and .NET are trademarks of Microsoft Corporation; IntelliJ IDEA and Rider are trademarks of JetBrains s.r.o. This page is not affiliated with or endorsed by Microsoft or JetBrains.
More: MSB3644: the reference assemblies were not found · the dotnet task matched no project · NuGet: Unable to load the service index for source · Unable to locate executable file · 日本語