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

swa*_*mle 9 azure-devops

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

我收到以下错误:

nuget 命令失败,出现退出代码 (1) 和错误(无法确定用于还原 NuGet 包的包文件夹。请指定 -PackagesDirectory 或 -SolutionDirectory。)包无法还原

有人可以帮我吗?

Leo*_*SFT 7

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

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

在此处输入图片说明

当我通过packages.config/project 文件恢复一个项目的 nuget 包时,我们应该在 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
Run Code Online (Sandbox Code Playgroud)

原因的错误:

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

希望这可以帮助。