首页 > 解决方案 > 无法在 Azure Devops 中仅构建解决方案的一个项目

问题描述

我正在尝试使用 Azure Devops 创建一个新的构建管道。我可以构建整个解决方案,但是我无法在同一个解决方案中为单个项目构建。

我收到以下错误:

nuget 命令失败,退出代码 (1) 和错误(无法确定包文件夹以恢复 NuGet 包。请指定 -PackagesDirectory 或 -SolutionDirectory。)包无法恢复

有人可以帮我吗?

标签: azure-devops

解决方案


在 Azure Devops 中仅构建解决方案的一个项目

要解决此问题,您应该为 nuget 指定一个目录来保存还原 nuget 包,例如:

在此处输入图像描述

当我通过 /project 文件恢复一个项目的 nuget 包时packages.config,我们应该在 nuget 恢复任务上扩展选项 Advanced,然后指定一个目录,我将其设置为默认包,..\packages. 然后我测试它,它恢复成功:

2019-02-01T06:18:22.1311238Z ##[section]Starting: NuGet restore

....

2019-02-01T06:18:28.3155511Z [command]C:\VSTS-vs2017-agent\_work\_tool\NuGet\4.3.0\x64\nuget.exe restore C:\VSTS-vs2017-agent\_work\5\s\TestSample\TestSample\TestSample.csproj -PackagesDirectory ..\packages -Verbosity Detailed -NonInteractive -ConfigFile C:\VSTS-vs2017-agent\_work\5\Nuget\tempNuGet_169.config

2019-02-01T06:18:37.0366771Z All packages listed in packages.config are already installed.
2019-02-01T06:18:37.0594978Z ##[section]Finishing: NuGet restore
2019-02-01T06:18:22.1311238Z ##[section]Starting: NuGet restore
2019-02-01T06:18:22.1319968Z ==============================================================================
2019-02-01T06:18:37.0366199Z C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin\msbuild.exe "C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\NuGetScratch\svd0ok2h.e2f.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\NuGetScratch\bhkdd2rf.itk.nugetrestore.targets" /p:RestoreTaskAssemblyFile="C:\VSTS-vs2017-agent\_work\_tool\NuGet\4.3.0\x64\nuget.exe" /p:RestoreConfigFile="C:\VSTS-vs2017-agent\_work\5\Nuget\tempNuGet_169.config" /p:RestorePackagesPath="..\packages"
2019-02-01T06:18:37.0366350Z 
2019-02-01T06:18:37.0366771Z All packages listed in packages.config are already installed.
2019-02-01T06:18:37.0594978Z ##[section]Finishing: NuGet restore

错误原因

当我们在 Azure Devops 中只为解决方案的一个项目构建或恢复 nuget 包时,nuget 将 nuget 包恢复到解决方案文件夹下的默认文件夹,但由于我们在构建/nuget 恢复任务中\packages没有指定文件,所以 nuget.sln不知道解决方案文件夹在哪里。然后nuget将抛出该错误。因此,我们应该为 nuget 指定一个目录来保存恢复的 nuget 包。

希望这可以帮助。


推荐阅读