dotnet build task failed

Viewed 1203

New to the forum as rookie, might ask something simple, please help me.

Running a yml pipeline by using a self hosted ado agent (Server 2019 data centre image). the dotnet build kees failing with the below error:

Build FAILED.

C:\agent_work_tool\dotnet\sdk\6.0.300\Microsoft.Common.CurrentVersion.targets(1221,5): error MSB3971: The reference assemblies for ".NETFramework,Version=v6.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK. [C:\agent_work\3\s\xxxxxxxx.xxxxxxxx.Tests.Api\xxxxxxxx.xxxxxxxx.Tests.Api\xxxxxxxx.xxxxxxxx.Tests.Api.csproj]

0 Warning(s)

1 Error(s)

Time Elapsed 00:00:00.40

I have checked the self hosted agent and make sure that dotnet 5 and 6 are both installed. still not working. tried almost everything but no luck.VS2022 is also installed (2017 and 2019 are installed parallel as well)

The reason we are using the self hosted agent is that the test task after build is needing to access some private endpint.

3 Answers

I got this exact error building a Container. The problem was this old image in the dockerflie:

FROM mcr.microsoft.com/dotnet/sdk:3.1-alpine AS build

This fixed it:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build

In my case I've had the same problem after converting the solution from netcore3.1 to .net6 by using the "Upgrade Assistant" tool from MS. At the end it appeared that the tool didn't converted one of the projects, and it was still left as netcore3.1. Even trying to convert that single project explicitly it didn't worked either. I just had to do that by hand and it solved the build issue.

Issue resolved. The MSBuild environment vairables was pointing to dotnet 3.1.249 and for some reason when dotnet 6 installed the variables were not updated even inside same folder. Manually updated the variable and restarted the agent service. It appreas in the agent capability list as 6. Build works now. Thank you eveyone. I guess rookie made a rookie mistake.

Related