Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot build only one project of a solution in Azure Devops

Tags:

azure-devops

I am trying to create a new build pipeline using Azure Devops. I can built the whole solution, however I am not able to build for a single project in the same solution.

I am getting the following error:

The nuget command failed with exit code(1) and error(Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.) Packages failed to restore

Can anybody please help me?

like image 836
swapnil kamle Avatar asked Jan 31 '19 11:01

swapnil kamle


People also ask

How many projects can you have in Azure DevOps?

Azure DevOps Services limits each organization to 1000 projects per organization, an increase over the previous limit of 300 projects.

What is $( BuildConfiguration?

Tip: Declare a build variable such as BuildConfiguration on the Variables tab (selecting Allow at Queue Time) and reference it here as $(BuildConfiguration) . This way you can modify the platform when you queue the build and enable building multiple configurations.

What is build SourcesDirectory in Azure DevOps?

Build.SourcesDirectory. The local path on the agent where your source code files are downloaded. For example: c:\agent_work\1\s. By default, new build pipelines update only the changed files.


1 Answers

Build only one project of a solution in Azure Devops

To resolve this issue, you should specify a directory for nuget to save the restore nuget packages, like:

enter image description here

When I restore the nuget packages for one project by packages.config/project file, we should expend the option Advanced on the nuget restore task, then specify a directory, I set it as default packages, ..\packages. Then I test it, it restored successfully:

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

The reason for the error:

When we only build or restore the nuget package for one project of a solution in Azure Devops, nuget restore the nuget packages to the default \packages folder under the solution folder, but since we do not specify the .sln file in the build/nuget restore task, nuget does not know where is the solution folder. Then nuget will throw that error. So, we should specify a directory for nuget to save the restore nuget packages.

Hope this helps.

like image 121
Leo Liu-MSFT Avatar answered Sep 23 '22 09:09

Leo Liu-MSFT