Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the Nuget restore work faster?

We are building CD pipeline using VSTS hosted build servers. It takes more than 3 minutes to restore Nuget. This is too much time.

How can I make it run faster? Is there any sort of caching system we can use?

like image 982
Rıfat Erdem Sahin Avatar asked Aug 31 '17 13:08

Rıfat Erdem Sahin


People also ask

How speed up NuGet restore?

Often the NuGet restore/npm install takes a couple of minutes to download all packages that you use in your solution. One way to speed up that process is to use the “new” Cache task in Azure DevOps.

Does Msbuild restore NuGet packages?

msbuild -t:Restore will restore nuget packages for projects with PackageReference nuget management format.

What is azure DevOps pipelines?

Azure Pipeline is a cloud service that we can use to build and test our code project automatically. The Azure pipeline has a lot of capabilities such as continuous integration and continuous delivery to regularly and consistently test and builds our code and ship to any target.


2 Answers

UPDATE: Caching is now generally available (docs)

Caching is currently on the feature pipeline with a TBD date. In the mean time you can use the Upload Pipeline Artifact/Download Pipeline Artifact tasks to store results in your Azure DevOps account to speed up up/downloads.

The Work-in-progress can be tracked here.

In the mean time, the Microsoft 1ES (one engineering system, internal organization) has released their internal solution that uses Universal Packages to store arbitrary packages in your Azure DevOps account. It's very fast because it can sync the delta between previous packages. There is a sample on how to configure your Azure Pipeline to store the NuGet package cache in your Sources Directory in order for the task to cache them.

variables:
  NUGET_PACKAGES: $(Build.SourcesDirectory)/packages
  keyfile: '**/*.csproj, **/packages.config, salt.txt'
  vstsFeed: 'feed name'

steps:
- task: 1ESLighthouseEng.PipelineArtifactCaching.RestoreCache@1
  displayName: 'Restore artifact'
  inputs:
    keyfile: $(keyfile)
    targetfolder: $(NUGET_PACKAGES)
    vstsFeed: $(vstsFeed)
like image 127
jessehouwing Avatar answered Sep 28 '22 07:09

jessehouwing


In my scenario, Nuget restore ran quickly when run interactively, but very slowly when run through CD pipeline (Jenkins). Setting revocation check mode to offline reduced my Nuget restore times from 13+ minutes to under 30 seconds (I found this solution here)

I set an environment variable in my build script prior to running Nuget restore:

  • SET NUGET_CERT_REVOCATION_MODE=offline

Disclaimer: Turning off certificate revocation has implications - see this link.

like image 28
Grits Avatar answered Sep 28 '22 06:09

Grits