Vignes
Vignes
CC#
Created by Vignes on 11/19/2024 in #help
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'
4 replies