Skip to content

Arcade overrides globalPackagesFolder to corrupt the shared NuGet cache #6720

@sharwell

Description

@sharwell

Steps to reproduce

  1. Create a local temporary build of some packages for testing

  2. Add the packages from (1) to <packageSources>

  3. Set globalPackagesFolder in NuGet.config to avoid having the packages from (1) corrupt the shared cache

    <config>
      <add key="globalPackagesFolder" value="./artifacts/package-cache" />
    </config>
  4. Restore the solution

Expected results

Arcade/NuGet restores packages to the ./artifacts/package-cache folder to avoid corrupting per-user cache with temporary artifacts.

Actual results

The restore process ignores this standard configuration property and corrupts the cache anyway.

It appears one of the following lines are responsible for this unexpected behavior:

<!-- Respect environment variable for the NuGet Packages Root if set; otherwise, use the current default location -->
<NuGetPackageRoot Condition="'$(NuGetPackageRoot)' != ''">$([MSBuild]::NormalizeDirectory('$(NuGetPackageRoot)'))</NuGetPackageRoot>
<NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == '' and '$(NUGET_PACKAGES)' != ''">$([MSBuild]::NormalizeDirectory('$(NUGET_PACKAGES)'))</NuGetPackageRoot>
<NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == '' and '$(OS)' == 'Windows_NT'">$([MSBuild]::NormalizeDirectory('$(UserProfile)', '.nuget', 'packages'))</NuGetPackageRoot>
<NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == '' and '$(OS)' != 'Windows_NT'">$([MSBuild]::NormalizeDirectory('$(HOME)', '.nuget', 'packages'))</NuGetPackageRoot>

arcade/eng/common/tools.ps1

Lines 543 to 558 in 2dcda00

function GetNuGetPackageCachePath() {
if ($env:NUGET_PACKAGES -eq $null) {
# Use local cache on CI to ensure deterministic build.
# Avoid using the http cache as workaround for https://github.com/NuGet/Home/issues/3116
# use global cache in dev builds to avoid cost of downloading packages.
# For directory normalization, see also: https://github.com/NuGet/Home/issues/7968
if ($useGlobalNuGetCache) {
$env:NUGET_PACKAGES = Join-Path $env:UserProfile '.nuget\packages\'
} else {
$env:NUGET_PACKAGES = Join-Path $RepoRoot '.packages\'
$env:RESTORENOCACHE = $true
}
}
return $env:NUGET_PACKAGES
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    dev-workflowProvides some benefit to dev workflow

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions