5

I'm creating a Azure DevOps pipeline, and I have a requirement to use .NET Core 3.1.

From the documentation, I can't see any obvious reference to the version of .NET Core that will be used with the DotNetCoreCLI task, so I gave it a try -

- task: DotNetCoreCLI@2
  name: Dotnet_Restore
  inputs:
    command: 'restore'
    feedsToUse: 'select'

This failed with the error The current .NET SDK does not support targeting .NET Core 3.1., but interestingly the logs state -

Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x SDK/Runtime along with 2.2 & 2.1.

With this is mind, I again looked at the documentation and came across the requestedMajor|Minor|PatchVersion parameters, so I updated my task -

- task: DotNetCoreCLI@2
  name: Dotnet_Restore
  inputs:
    command: 'restore'
    feedsToUse: 'select'
    requestedMajorVersion: '3'
    requestedMinorVersion: '1'

Sadly this also failed, with the same 'Info' statement as above.

David Gard
  • 11,225
  • 36
  • 115
  • 227
  • Found a similar question here - https://stackoverflow.com/questions/56574113/build-net-core-3-0-on-azure-pipelines – David Gard Feb 10 '20 at 13:42

1 Answers1

12

The UseDotNet task seems to be what I need here, with the description stating -

Use this task in a build or release pipeline to acquire a specific version of .NET Core from the Internet or the tools cache and add it to the PATH.

You can also use this task to change the version of .NET Core used in subsequent tasks like .NET Core cli task.

To test, I added a new task to the beginning of my pipeline, requesting .NET Core version 3.1.101 -

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: sdk
    version: 3.1.x
    installationPath: $(Agent.ToolsDirectory)/dotnet

Important Note

If you use the DotNetCoreCLI task in more than one job, you have to include the UseDotNet task at the beginning of each of those jobs. This is mighty inconvinient and hopefully something that can be improved in the future.

Community
  • 1
  • 1
David Gard
  • 11,225
  • 36
  • 115
  • 227