VSTS - System.InvalidOperationException:无法确定还原 NuGet 包的文件夹。指定 -PackagesDirectory 或 -SolutionDirectory

VSTS - System.InvalidOperationException: Can't determine the folder to restore NuGet packages. Specify either -PackagesDirectory or -SolutionDirectory

我有一个 Visual Studio 2017 解决方案,其中包括 2 个项目。一个项目使用 .NET 4.7.1。另一个项目使用 .NET Core。我有兴趣在 VSTS 中自动构建我的 .NET 4.7.1 项目。但是,此时,我的构建失败并显示错误:

The nuget command failed with exit code(1) and error(System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.
   at NuGet.CommandLine.RestoreCommand.GetPackagesFolder(PackageRestoreInputs packageRestoreInputs)
   at NuGet.CommandLine.RestoreCommand.<PerformNuGetV2RestoreAsync>d__35.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NuGet.CommandLine.RestoreCommand.<ExecuteCommandAsync>d__30.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at NuGet.CommandLine.Command.Execute()
   at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)
---> (Inner Exception #0) System.InvalidOperationException: Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.
   at NuGet.CommandLine.RestoreCommand.GetPackagesFolder(PackageRestoreInputs packageRestoreInputs)
   at NuGet.CommandLine.RestoreCommand.<PerformNuGetV2RestoreAsync>d__35.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NuGet.CommandLine.RestoreCommand.<ExecuteCommandAsync>d__30.MoveNext()<---)
Packages failed to restore

此故障发生在我的 VSTS 构建管道中的第一个任务期间。该任务使用以下属性定义:

Command: restore
Path to solution, packages.config, or project.json: MyNet471Project/MyNet471Project.csproj
Feeds to use: Feed(s) I select here - <My Private NuGet repo>
Disable local cache is not checked

我不明白为什么我会遇到这个问题。我错过了什么?

更新 值得注意的是,我删除了解决方案级别的 "packages" 目录和本地计算机上的 "bin" 目录。当我在 Visual Studio 中重建解决方案时,Visual Studio 自动获取包并成功构建。

但是,如果我从命令行 运行 nuget restore MyNet471Project/MyNet471Project.csproj,我会收到与我在 VSTS 中看到的类似的错误。命令行中的错误显示:

Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.

什么是Visual Studio运行自动恢复包?

从错误消息来看,MyNet471Project.csproj 所在的位置似乎没有 packages.configproject.json 文件。

在字段 Path to solution, packages.config, or project.json: 中尝试给出 packages.configproject.json 文件本身的路径而不是 MyNet471Project.csproj,或者给出解决方案的路径packages.config 存在于同一文件夹中。

我向 "Destination directory" 属性 添加了一个值,它成功了!