9

I developed WebAPI project using .NET Core 3.1.0 and integration tests using XUnit.

I added the below task in Azure DevOps CI Pipeline (azure-pipelines.yaml) to run the integration tests project.

 - task: DotNetCoreCLI@2
   displayName: 'Run API integration tests - $(buildConfiguration)'
   inputs:
    command: 'test'
    arguments: '--configuration $(buildConfiguration)'
    publishTestResults: true
    projects: '**/IntegrationTests/IntegrationTests.csproj'

I got the below error during pipeline execution. How to resolve this error?

##[error]Error: The process '/usr/bin/dotnet' 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://learn.microsoft.com/en-us/dotnet/core/tools/ and https://learn.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://learn.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 : /home/vsts/work/1/s/src/IntegrationTests/IntegrationTests.csproj

3
  • Not get your latest information, is Krzysztof Madej's workaround helpful for you? Or if you have any concern, feel free to share it here.
    – Hugh Lin
    Nov 27, 2020 at 6:36
  • Try to use the nuget version 5.8 to restore.
    – Leo Liu
    Nov 27, 2020 at 6:55
  • Have the same issue. It is strange that the task completessuccesfully if it is not in a template, but fails when I move it to the template yml file. The answer from Krzysztof Madej did not help me Dec 10, 2020 at 5:34

2 Answers 2

1

I've had a smiller issue but with .netcore 2.2. The problem was that the test tries to build before the test starts restoring the packages for the test, thus fails before the test runs or builds. One thinge that help me overcome this problem was this FAQ:

Most dotnet commands, including build, publish, and test include an implicit restore step. This will fail against authenticated feeds, even if you ran a successful dotnet restore in an earlier step, because the earlier step will have cleaned up the credentials it used. To fix this issue, add the --no-restore flag to the Arguments textbox.

I've also read that the DotNetCLI had some issues when it came to tests like this one here

So I ended up using a script to solve this and other issues related to package restore.

- script: dotnet test '**/IntegrationTests/IntegrationTests.csproj' --configuration $(buildConfiguration) --logger trx;LogFileName=C:\temp\results
  displayName: 'Run API integration tests - $(buildConfiguration)'

I hope that will help you or anyone who has similar issues.

0

I've had exactly the same problem, with the difference that my solution consisted of .net5 apps as well as .netcore3.1 apps.

I was able to solve this problem by specifying the newer dotnet runtime in the azure pipeline:

- task: UseDotNet@2
  inputs:
    version: '5.0.x'
    packageType: runtime
2
  • Is there an equivalent to this step for the classic pipeline editor?
    – Echilon
    Nov 11, 2022 at 15:58
  • 1
    Yes, try to search for "Use .NET Core" task. The task allows you to specify the version and the package to install (SDK or runtime only)
    – ddegasperi
    Nov 14, 2022 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.