Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to use .NET SDK agent in Azure DevOps Build Pipeline

I have a ASP.NET Core 2.1 and added a nuget package of Microsoft.WindowsAzure.Storage , But after pushing the code to repo, the build pipeline occurs package error while running the build agent and is it necessary to add any other agents in build pipeline other than BUILD, RESTORE, TEST and PUBLISH.

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

Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x SDK/Runtime along with 2.2 & 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions.

This is the error it shows while running the pipeline.

like image 905
Vignesh Arvind Avatar asked Dec 25 '19 00:12

Vignesh Arvind


People also ask

How do I install .NET framework in Azure pipeline?

Sign in to Azure Pipelines After you sign in, your browser goes to https://dev.azure.com/my-organization-name and displays your Azure DevOps dashboard. Within your selected organization, create a project. If you don't have any projects in your organization, you see a Create a project to get started screen.


3 Answers

As the error info indicates, it's not recommended to call latest 3.x sdk to restore,build,test,publish your project that targets asp .net core 2.1.

Though in most of time the build can pass, but the Publish step(task) may encounter this issue:

enter image description here

To resolve the issue:

We should specify the .net core sdk version we want to use before running tasks like restore,build,test,publish...

We could add a use .net core sdk task before other .net core tasks like this to pick up the .net core 2.1.x related version to do the following tasks instead of using .net core 3.x sdk:

Classic UI:

enter image description here

Specify 2.1.x+Include Preview Versions will pick up the latest version of 2.1 sdk.

Yaml:

In case you're using yaml format instead of classic UI format to configure the pipeline, its yaml format looks similar to this:

steps:
- task: UseDotNet@2
  displayName: 'Use .Net Core sdk 2.1.x'
  inputs:
    packageType: sdk
    version: 2.1.x
    installationPath: $(Agent.ToolsDirectory)/dotnet
    includePreviewVersions: true

Hope it helps and feel free to correct me if I misunderstand anything:)

like image 118
LoLance Avatar answered Oct 04 '22 21:10

LoLance


I encountered the same issue with version 2.1.505 and now I am using the following configuration for variables and installer step for .NET Core in my yaml pipeline while using version 3.1.101 and it fixed my issue.

variables:
  buildConfiguration: 'Release'
  dotnetSdkVersion: '3.1.101'

steps:
- task: DotNetCoreInstaller@0
  displayName: 'Use .NET Core SDK $(dotnetSdkVersion)'
  inputs:
    version: '$(dotnetSdkVersion)'
like image 33
faur8 Avatar answered Oct 04 '22 21:10

faur8


The following steps worked for me:

  • Add a task before restore task named "Use .Net Core"
  • Specify intended sdk version ending with 'x'. For example 2.x
  • Check "Include Preview Versions" option
like image 25
Meghnath Das Avatar answered Oct 04 '22 21:10

Meghnath Das