From 1dc6b0e2dd4d39b9a5f86b5d359f05474c6585eb Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Thu, 9 Jun 2016 15:05:27 -0700 Subject: [PATCH] Make the nuget cache local to the repo (#3370) * fixes #3368 * Update build nuget cache to be in the repo --- .gitignore | 3 +++ .../dotnet-cli-build/PrepareTargets.cs | 18 +++--------------- build_projects/dotnet-cli-build/build.ps1 | 1 + build_projects/dotnet-cli-build/build.sh | 3 +++ .../shared-build-targets-utils/Utils/Dirs.cs | 6 +----- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index cca89b49e..bae5bb22d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ # NuGet keeps dropping Library/ +# local nuget cache +.nuget/ + # NuGet v3 restore drops these even though we don't use MSBuild :( *.nuget.targets *.nuget.props diff --git a/build_projects/dotnet-cli-build/PrepareTargets.cs b/build_projects/dotnet-cli-build/PrepareTargets.cs index 566eabc73..98c776947 100644 --- a/build_projects/dotnet-cli-build/PrepareTargets.cs +++ b/build_projects/dotnet-cli-build/PrepareTargets.cs @@ -261,21 +261,9 @@ namespace Microsoft.DotNet.Cli.Build public static BuildTargetResult CheckPackageCache(BuildTargetContext c) { var ciBuild = string.Equals(Environment.GetEnvironmentVariable("CI_BUILD"), "1", StringComparison.Ordinal); - - if (ciBuild) - { - // On CI, HOME is redirected under the repo, which gets deleted after every build. - // So make NUGET_PACKAGES outside of the repo. - var nugetPackages = Path.GetFullPath(Path.Combine(c.BuildContext.BuildDirectory, "..", ".nuget", "packages")); - Environment.SetEnvironmentVariable("NUGET_PACKAGES", nugetPackages); - Dirs.NuGetPackages = nugetPackages; - } - - // Set the package cache location in NUGET_PACKAGES just to be safe - if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NUGET_PACKAGES"))) - { - Environment.SetEnvironmentVariable("NUGET_PACKAGES", Dirs.NuGetPackages); - } + + // Always set the package cache location local to the build + Environment.SetEnvironmentVariable("NUGET_PACKAGES", Dirs.NuGetPackages); CleanNuGetTempCache(); diff --git a/build_projects/dotnet-cli-build/build.ps1 b/build_projects/dotnet-cli-build/build.ps1 index 0f27922a7..73f5f5e9d 100644 --- a/build_projects/dotnet-cli-build/build.ps1 +++ b/build_projects/dotnet-cli-build/build.ps1 @@ -25,6 +25,7 @@ if($Help) $env:CONFIGURATION = $Configuration; $RepoRoot = "$PSScriptRoot\..\.." +$env:NUGET_PACKAGES = "$RepoRoot\.nuget\packages" if($NoPackage) { diff --git a/build_projects/dotnet-cli-build/build.sh b/build_projects/dotnet-cli-build/build.sh index 412013fef..2ec1a8a24 100755 --- a/build_projects/dotnet-cli-build/build.sh +++ b/build_projects/dotnet-cli-build/build.sh @@ -57,6 +57,9 @@ while [[ $# > 0 ]]; do shift done +# Set nuget package cache under the repo +export NUGET_PACKAGES="$REPOROOT/.nuget/packages" + # Set up the environment to be used for building with clang. if which "clang-3.5" > /dev/null 2>&1; then export CC="$(which clang-3.5)" diff --git a/build_projects/shared-build-targets-utils/Utils/Dirs.cs b/build_projects/shared-build-targets-utils/Utils/Dirs.cs index b602469cd..5e5f9d3a5 100644 --- a/build_projects/shared-build-targets-utils/Utils/Dirs.cs +++ b/build_projects/shared-build-targets-utils/Utils/Dirs.cs @@ -45,11 +45,7 @@ namespace Microsoft.DotNet.Cli.Build private static string GetNuGetPackagesDir() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), ".nuget", "packages"); - } - return Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".nuget", "packages"); + return Path.Combine(Dirs.RepoRoot, ".nuget", "packages"); } } }