Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the nuget packages folder located on a hosted build server using TFS?

I need to execute a command line utility from a package that is downloaded as part of nuget package restore in the TFS build process.

On my local computer that is stored in c:\users\me.nuget*

I've tried every permutation of that on TFS without success. I've also tried \mydir\packages with no success as well.

The biggest problem is that I have to run the package restore step before being able to see any sort of feedback from the log. That's some slow debugging.

Any ideas? Thanks ahead.

like image 747
trevorc Avatar asked Jan 10 '17 01:01

trevorc


3 Answers

With the latest nuget/msbuild the packages folder is held under the active user's profile directory, so an appropriate Powershell command is

Get-ChildItem $(UserProfile)\.nuget\packages 

This currently evaluates on the VSTS 2017 Hosted build agent to C:\Users\VssAdministrator\.nuget\packages but by using the variable you are insulated from any changes made.

like image 146
Paul Hatcher Avatar answered Oct 11 '22 18:10

Paul Hatcher


Just an addition to @Paul Hatcher's answer:

I also faced the same problem in Azure DevOps build pipeline where a specific package and nuget packages directory could not be found. It is a Xamarin.Forms app based on a .net standard library where no packages folder exists. I later noticed in build logs that the packages are restored to nuget folder under user's profile. However this particular case is not documented on https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=vsts#agent-variables.

enter image description here

That means @Paul Hatcher's answer is also valid if you try to reference nuget package folder directly from your build pipeline. This ($(UserProfile).nuget\packages) should actually be a (standard) predefined build variable.

like image 37
I.C Avatar answered Oct 11 '22 20:10

I.C


The Nuget package cache folder is in C:\Users\buildguest.nuget\packages, but it will be cleaned after build if you are using Hosted build server. The simple way to verify:

  1. Add NuGet restore or .Net Core Restore build step to restore packages
  2. Add PowerShell build step to list files in C:\Users\buildguest.nuget\packages

Code:

Get-ChildItem -Path C:\Users\buildguest\.nuget\packages
  1. Queue build and check the PowerShell step log (the packages’ will be listed in the log)
  2. Remove/disable NuGet restore or .Net Core Restore build step > Save build definition
  3. Queue build
  4. The build will be failed, because the path does not exist.

So, the packages need to be restored before build solution/project if aren’t existing. You can add packages to source control and map to build agent to deal with the issue of too long time takes to restore packages.

like image 28
starian chen-MSFT Avatar answered Oct 11 '22 18:10

starian chen-MSFT