How to make the Nuget restore work faster?

13.5k views Asked by At

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?

2

There are 2 answers

1
Grits On

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.

3
jessehouwing On

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)