首页 > 解决方案 > Azure Pipelines 在 NuGet 还原阶段失败

问题描述

我正在使用 Image vs2017-win2016 进行构建,作为构建的一部分,我有 Nuget 还原任务,该任务失败并显示以下错误消息。有人可以告诉我这里出了什么问题以及我们如何解决它吗?这是一个简单的 Asp.Net Web 应用程序。

2021-06-25T09:01:16.6036745Z ##[section]Starting: NuGet restore
2021-06-25T09:01:16.6136450Z ==============================================================================
2021-06-25T09:01:16.6136733Z Task         : NuGet
2021-06-25T09:01:16.6137224Z Description  : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
2021-06-25T09:01:16.6137701Z Version      : 2.179.0
2021-06-25T09:01:16.6138100Z Author       : Microsoft Corporation
2021-06-25T09:01:16.6138522Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/nuget
2021-06-25T09:01:16.6138831Z ==============================================================================
2021-06-25T09:01:17.3136968Z SYSTEMVSSCONNECTION exists true
2021-06-25T09:01:17.4377830Z SYSTEMVSSCONNECTION exists true
2021-06-25T09:01:17.8046121Z [command]C:\Windows\system32\chcp.com 65001
2021-06-25T09:01:17.8104107Z Active code page: 65001
2021-06-25T09:01:17.8631847Z Detected NuGet version 4.4.1.4656 / 4.4.1
2021-06-25T09:01:17.8642220Z SYSTEMVSSCONNECTION exists true
2021-06-25T09:01:17.8812714Z [command]C:\hostedtoolcache\windows\NuGet\4.4.1\x64\nuget.exe sources Add -NonInteractive -Name NuGetOrg -Source https://api.nuget.org/v3/index.json -ConfigFile D:\a\1\Nuget\tempNuGet_31.config
2021-06-25T09:01:19.1590360Z Package Source with Name: NuGetOrg added successfully.
2021-06-25T09:01:19.1660433Z [command]C:\hostedtoolcache\windows\NuGet\4.4.1\x64\nuget.exe restore D:\a\1\s\VSDemoPipeline.sln -Verbosity Detailed -NonInteractive -ConfigFile D:\a\1\Nuget\tempNuGet_31.config
2021-06-25T09:01:47.4269841Z C:\Program Files\dotnet\sdk\2.1.524\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1.  Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. [D:\a\1\s\VSDemoPipeline\VSDemoPipeline.csproj]
2021-06-25T09:01:47.4271151Z 
2021-06-25T09:01:47.4279527Z NuGet Version: 4.4.1.4656
2021-06-25T09:01:47.4280682Z MSBuild auto-detection: using msbuild version '15.9.21.664' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
2021-06-25T09:01:47.4281803Z MSBuild P2P timeout [ms]: 120000
2021-06-25T09:01:47.4283437Z C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\msbuild.exe "C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\4rucjvrx.krk.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\opqnszhe.dir.nugetrestore.targets" /p:RestoreTaskAssemblyFile="C:\hostedtoolcache\windows\NuGet\4.4.1\x64\nuget.exe" /p:RestoreSolutionDirectory="D:\a\1\s" /p:RestoreConfigFile="D:\a\1\Nuget\tempNuGet_31.config" /p:SolutionDir="D:\a\1\s"
2021-06-25T09:01:47.4289820Z NuGet.CommandLine.ExitCodeException: Exception of type 'NuGet.CommandLine.ExitCodeException' was thrown.
2021-06-25T09:01:47.4334578Z    at NuGet.CommandLine.MsBuildUtility.<GetProjectReferencesAsync>d__6.MoveNext()
2021-06-25T09:01:47.4335343Z --- End of stack trace from previous location where exception was thrown ---
2021-06-25T09:01:47.4335807Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2021-06-25T09:01:47.4336289Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2021-06-25T09:01:47.4336788Z    at NuGet.CommandLine.RestoreCommand.<GetDependencyGraphSpecAsync>d__48.MoveNext()
2021-06-25T09:01:47.4337172Z --- End of stack trace from previous location where exception was thrown ---
2021-06-25T09:01:47.4337555Z    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2021-06-25T09:01:47.4337950Z    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2021-06-25T09:01:47.4339708Z    at NuGet.CommandLine.RestoreCommand.<DetermineInputsFromMSBuildAsync>d__43.MoveNext()
2021-06-25T09:01:47.4855912Z ##[error]The nuget command failed with exit code(1) and error(C:\Program Files\dotnet\sdk\2.1.524\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1.  Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. [D:\a\1\s\VSDemoPipeline\VSDemoPipeline.csproj])
2021-06-25T09:01:47.4866755Z ##[error]Packages failed to restore
2021-06-25T09:01:47.4877131Z ##[section]Finishing: NuGet restore

标签: azure-devopsnugetazure-pipelines

解决方案


若要在 NET Core 3.1 或更高版本上构建 APS.NET 应用,请windows-latest在 Azure DevOps 中使用代理。

旧版本的代理不支持它,如果您注意到错误,它也很明显。

nuget 命令失败,退出代码 (1) 和错误(C:\Program Files\dotnet\sdk\2.1.524\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5):错误 NETSDK1045:当前 .NET SDK 不支持面向 .NET Core 3.1。要么面向 .NET Core 2.1 或更低版本,要么使用支持 .NET Core 3.1 的 .NET SDK 版本。[D:\a\1\ s\VSDemoPipeline\VSDemoPipeline.csproj]) 2021-06-25T09:01:47.4866755Z ##[错误]包无法恢复

在管道中,确保您具有适当版本的“使用 Dotnet Core”任务:

使用 Dotnet Core 任务


推荐阅读