21

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.

Community
  • 1
  • 1
Vignesh Arvind
  • 531
  • 2
  • 7
  • 16
  • Adding a `use .net core` task in which specify the version with `2.1.x` before your `restore, build, test, publish task`, the issue would go away. – LoLance Dec 25 '19 at 02:14

4 Answers4

25

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:)

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • It still occurs the same error while using 2.1.x...So can i use 3.x ?? – Vignesh Arvind Dec 25 '19 at 04:16
  • Does the error occurs in build or publish step(for me, it's there when I try to reproduce the issue)? It's not recommended to use 3.x, cause your original issue occurs when it picks .net core 3 for your pipeline while your project targets .net core 2.1. Trying using a exact version [here](https://dotnet.microsoft.com/download/dotnet-core/2.1), like 2.1.802... – LoLance Dec 25 '19 at 04:44
  • Again 3.x also occurs same error ... ##[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. Some commonly encountered changes are: – Vignesh Arvind Dec 25 '19 at 04:46
  • Please check the log of `Use .net core sdk task`, do you see something like `Successfully installed .NET Core sdk version 2.1.802.` there? Make sure you're using windows OS hosted agent. – LoLance Dec 25 '19 at 04:47
  • Yes...the .NET core SDK was installed successfully and i've used windows 2019 as hosted agent ....but still didn't worked – Vignesh Arvind Dec 25 '19 at 04:54
  • If you want i can share my YAML – Vignesh Arvind Dec 25 '19 at 04:59
  • @VigneshArvind You can share it in your question by updating the question. And just to make sure, if you use .net core 2.1.802, the error info `Azure Pipelines hosted agents have been updated to contain .Net Core 3.x SDK/Runtime along with 2.2 & 2.1. ` still exists? Is there any possibility that `but still didn't worked ` refers to another issue that generates the `dotnet.exe exit error`? – LoLance Dec 25 '19 at 05:22
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/204821/discussion-between-vignesh-arvind-and-lance-li-msft). – Vignesh Arvind Dec 25 '19 at 05:25
  • I'm having the same issue with Restore task. Tried to use .net sdk 2.2.x but the issue remain – Mohamad Mousheimish Feb 13 '20 at 07:16
  • What framework version does your project target locally? – LoLance Feb 13 '20 at 07:21
  • Have u fixed the issue? @Vignesh Arvind – Oleksandr Fentsyk Mar 02 '20 at 11:38
  • @OleksandrFentsyk Not yet ...still it occurs same error – Vignesh Arvind Mar 02 '20 at 12:02
  • I am getting the same issue, is there a solution. – Santhosh Jun 30 '20 at 10:08
  • @Santhosh Does your project uses .net core 2.2? – LoLance Jun 30 '20 at 10:12
  • @LanceLi-MSFT Yes, we use .net core 2.2 – Santhosh Jun 30 '20 at 10:13
8

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)'
faur8
  • 91
  • 3
2

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
Meghnath Das
  • 145
  • 1
  • 6
  • Make sure to check your SDK version https://learn.microsoft.com/en-us/dotnet/core/install/how-to-detect-installed-versions?pivots=os-windows and plug the latest version into the task's version – Kris Kilton Apr 14 '20 at 16:06
-1

Add this line in .csproj, into PropertyGroup tag

<TargetLatestRuntimePatch>false</TargetLatestRuntimePatch>