C
C#3d ago
Vignes

NuGetCommand@2 restore always picks some old .NET SDK version on custom agent

I have a solution with projects of both old and new .net. When I try to restore the solution as a whole i always get some error like this
##[error]The nuget command failed with exit code(1) and error(c:\w\_tool\dotnet\sdk\6.0.428\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 8.0. [c:\w\21\s\Webjobs\<proj_name>\<proj_name>.csproj]
##[error]The nuget command failed with exit code(1) and error(c:\w\_tool\dotnet\sdk\6.0.428\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(144,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 8.0. Either target .NET 6.0 or lower, or use a version of the .NET SDK that supports .NET 8.0. [c:\w\21\s\Webjobs\<proj_name>\<proj_name>.csproj]
This is running on a custom agent with multiple sdks installed and this is a sample code
- task: UseDotNet@2
displayName: 'Install .NET SDK 8.0'
inputs:
packageType: 'sdk'
version: '$(sdk_version)'
installationPath: '$(Agent.ToolsDirectory)/dotnet'

- task: NuGetCommand@2
displayName: NuGet restore
inputs:
command: 'restore'
restoreSolution: 'MySoln.sln'
feedsToUse: 'config'
nugetConfigPath: 'NuGet.config'
- task: UseDotNet@2
displayName: 'Install .NET SDK 8.0'
inputs:
packageType: 'sdk'
version: '$(sdk_version)'
installationPath: '$(Agent.ToolsDirectory)/dotnet'

- task: NuGetCommand@2
displayName: NuGet restore
inputs:
command: 'restore'
restoreSolution: 'MySoln.sln'
feedsToUse: 'config'
nugetConfigPath: 'NuGet.config'
1 Reply
Vignes
VignesOP3d ago
same happens when i try to use VSBuild to build the whole solution ive been at this for weeks now so any help is appreciated also yea, i tried using this code on a normal windows pool and everything worked fine
Want results from more Discord servers?
Add your server