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

时间:2018-08-25 11:46:24

标签: azure-devops nuget-package azure-pipelines nuget-package-restore

我有一个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自动还原软件包?

2 个答案:

答案 0 :(得分:0)

根据错误消息,看来packages.config所在的project.jsonMyNet471Project.csproj文件没有。

在字段Path to solution, packages.config, or project.json:中尝试提供指向packages.configproject.json文件本身而不是MyNet471Project.csproj的路径,或者给出指向{{ 1}}存在于同一文件夹中。

答案 1 :(得分:0)

我在“目标目录”属性中添加了一个值,并且它起作用了!