Reputation: 41
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.
Upvotes: 3
Views: 6442
Reputation: 1757
use cmd and run this query, it returns installed .NET SDKs and .NET Runtimes
dotnet --info
check if SDK which you need is in the list, if not install it, before that, pay attention to what version (x86/x64) of Visual Studio you have installed and what version (x86/x64) of the SDK you are installing, If it does not match, there will be an error again
Upvotes: 0
Reputation: 29
sorry, I don't have enough reps to comment on xuy22's answer, so just adding to that, the environment variable name is MSBuildSDKsPath
Upvotes: 1
Reputation: 65702
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
Upvotes: 4
Reputation: 41
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.
Upvotes: 1
Reputation: 1776
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.
Upvotes: 0