2
votes

I have a project that builds using the following frameworks:

<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0</TargetFrameworks>

This compiles just fine on my local machine, but when I push it to Azure, it fails.

When I have the following in my YAML file:

variables:
  solution: '**/*.sln'
  buildConfiguration: 'Release'
  buildPlatform: 'Any CPU'
  platform: x64

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

Then I get:

##[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

And if I try

- task: VSBuild@1
  displayName: 'Build all'
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    maximumCpuCount: true

I get:

##[error]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\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

  1. The developer packs documentation refer only to the older .Net Framework, so I suspect this is irrelevant/outdated.
  2. This works fine if I change .Net 5 for .Net Core 3.1, i.e. <TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
2

2 Answers

2
votes

The reason your project doesn't build successfully is because the Microsoft-Hosted agent doesn't have the.NET 5.0 SDK installed.

You can download the.NET 5.0 SDK using Use.NET Core Task:

- task: UseDotNet@2
inputs:
packageType: 'sdk'
Version: '{version}'
includePreviewVersions: {true/false}

This task can download a specific version of the .Net SDK from the network and add it to the PATH.

In addition, since you are using multiple versions of .NET in your project, you can use this task to specify which version of.NET you will use in the following tasks.

In other words, this task has two functions:

  1. Download a specific SDK version that is not installed.
  2. Specify which SDK version will be used for the following tasks.
1
votes

I think there is a problem with build agent machines.

If you use cloud azure devops you need to wait when they will update their build machines.

If you use on premise azure devops try to update build machines by yourself.