29

I'm trying to build a project in .NET 5.0 using Azure DevOps pipeline Build and I'm received this error

Error image

2020-11-14T01:59:45.8238544Z [command]"C:\Program Files\dotnet\dotnet.exe" build D:\a\1\s\XXX.csproj "-dl:CentralLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.178.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"D:\a\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.178.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\""
2020-11-14T01:59:46.1472016Z Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
2020-11-14T01:59:46.1473316Z Copyright (C) Microsoft Corporation. All rights reserved.
2020-11-14T01:59:46.1473902Z 
2020-11-14T01:59:46.6006398Z   Determining projects to restore...
2020-11-14T01:59:47.2059773Z   Restored D:\a\1\s\XXX.csproj (in 234 ms).
2020-11-14T01:59:47.2119638Z   1 of 2 projects are up-to-date for restore.

    2020-11-14T01:59:47.3209350Z ##[error]C:\Program Files\dotnet\sdk\3.1.403\Microsoft.Common.CurrentVersion.targets(1177,5): Error MSB3644: The reference assemblies for .NETFramework,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

2020-11-14T01:59:47.3261839Z C:\Program Files\dotnet\sdk\3.1.403\Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [D:\a\1\s\XXX.csproj]
2020-11-14T01:59:47.3270768Z 
2020-11-14T01:59:47.3274231Z Build FAILED.
2020-11-14T01:59:47.3275925Z 
2020-11-14T01:59:47.3277393Z C:\Program Files\dotnet\sdk\3.1.403\Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [D:\a\1\s\XXX.csproj]
2020-11-14T01:59:47.3279484Z     0 Warning(s)
2020-11-14T01:59:47.3279860Z     1 Error(s)
2020-11-14T01:59:47.3280170Z 
2020-11-14T01:59:47.3280537Z Time Elapsed 00:00:01.09
2020-11-14T01:59:47.3624731Z ##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1

Does someone know if Azure DevOps pipelines have support for building .NET 5.0 code ?

Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
Danillo Parreira
  • 415
  • 1
  • 4
  • 6

4 Answers4

44

Yes, Azure DevOps Pipelines can build net5.0 apps.

If you are building with ".Net Core" (DotNetCoreCLI in yaml) task - add "Use .NET Core" (UseDotNet in yaml) task before it, with correct version:

- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '5.0.x'

- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    command: 'build'
Dmitry
  • 16,110
  • 4
  • 61
  • 73
12

It's supported.

Since you are using .Net 5, instead of using Nuget restore, try to use Use .net core taskand Dotnet core task with restore command.

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 5.0.100'
  inputs:
    packageType: 'sdk'
    version: '5.0.100'
    includePreviewVersions: true

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'

It's strongly recommended to use dotnet restore and dotnet build tasks for projects that target .net core. See this statement from Nuget task:

Also take a look at this similar question here: Azure CI pipeline for Blazor .NET 5 doesn't work

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
0

Hope this answer will help people who are still using "Classic Pipelines" (not yaml) in Azure DevOps.

There is exactly the same task template to set the specific version of .net core sdk, that can be added through the search dialog:

Use .Net Core

Include it in your pipeline and set the correct version through the UI. Also make sure it runs before the actual build/publish steps.

kudoku
  • 121
  • 6
-1

I needed to use both framework version to build my function in .net 5

steps:

- task: UseDotNet@2
  inputs:
    version: '5.0.x'
    packageType: sdk
    includePreviewVersions: false

- task: UseDotNet@2
  inputs:
    version: '3.1.x'
    packageType: sdk
    includePreviewVersions: false
Felipe Augusto
  • 1,341
  • 1
  • 16
  • 18
  • From my experience, having to do that seems quite implausible. – Zimano Aug 04 '22 at 11:23
  • If you are using .NET 5 - you will not be able to run your pipeline without points to two frameworks. Try it and tell me the result – Felipe Augusto Aug 11 '22 at 12:52
  • We're using .NET 5, and I've been setting up pipelines all week. You can check the other answers to see that this isn't needed. If you need some help, maybe we can start a chat, and I'll show you my approach. – Zimano Aug 15 '22 at 14:34
  • @Zimano I needed to use this for build Azure Functions, but not now a day, a few time ago. Perhapers now a days Azure DevOps and new versions of .NET updated to resolve this problem. – Felipe Augusto Aug 17 '22 at 10:09