Skip to content

Instantly share code, notes, and snippets.

@javafun
Forked from jraps20/build.yml
Created June 18, 2020 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javafun/014bfe20fbb178002976f8e48e9729f4 to your computer and use it in GitHub Desktop.
Save javafun/014bfe20fbb178002976f8e48e9729f4 to your computer and use it in GitHub Desktop.
Cache NuGet Packages with Cache Task in Azure DevOps YAML
- powershell: | # generates a hash of all packages.config and saves each on a single line on 'hash.txt'
Get-FileHash -Algorithm MD5 -Path (Get-ChildItem packages.config -Recurse) >> hash.txt
Write-Host "Hash File saved to $pwd\hash.txt"
workingDirectory: src
displayName: 'Calculate and save packages.config hash'
- task: CacheBeta@0 # speed up builds by caching packages folder
inputs:
key: nuget|1|$(Agent.OS)|$(Build.SourcesDirectory)\src\hash.txt # hash map generated in previous step
path: $(Build.SourcesDirectory)\src\packages
cacheHitVar: 'nuget_cache_hit' # variable that can be checked to see if it was successful
displayName: Cache nuget packages
continueOnError: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment