dotnet-installer/scripts/build/restore-packages.ps1
Eric Erhardt 617af759ae Cache NuGet packages on our CI server between builds.
Currently on our CI builds, we point our NuGet cache under the repo. In between builds the repo gets deleted, thus the cache is lost.

This change moves the cache to %userprofile%\.nuget\packages on CI and dev boxes.  On CI, we expire the cache after a day by default.
2016-02-05 10:34:20 -06:00

34 lines
1.2 KiB
PowerShell

#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
. $PSScriptRoot\..\common\_common.ps1
if ($env:CI_BUILD -eq "1") {
# periodically clear out the package cache on the CI server
$PackageCacheFile = "$env:NUGET_PACKAGES\packageCacheTime.txt"
if(!(Test-Path $PackageCacheFile)) {
Get-Date | Out-File -FilePath $PackageCacheFile
}
else {
$PackageCacheTimeProperty = Get-ItemProperty -Path $PackageCacheFile -Name CreationTimeUtc
$PackageCacheTime = [datetime]($PackageCacheTimeProperty).CreationTimeUtc
if ($PackageCacheTime -lt ([datetime]::UtcNow).AddHours(-$env:NUGET_PACKAGES_CACHE_TIME_LIMIT)) {
header "Clearing package cache"
Remove-Item -Recurse -Force "$env:NUGET_PACKAGES"
mkdir $env:NUGET_PACKAGES | Out-Null
Get-Date | Out-File -FilePath $PackageCacheFile
}
}
}
# Restore packages
# NOTE(anurse): I had to remove --quiet, because NuGet3 is too quiet when that's provided :(
header "Restoring packages"
& dotnet restore "$RepoRoot\src" --runtime "$Rid"
& dotnet restore "$RepoRoot\tools" --runtime "$Rid"