Skip to content

Commit

Permalink
Update NuGet global packages cache detection
Browse files Browse the repository at this point in the history
Make sure to account for per-user NuGet.Config as a way to configure the
location of the global packages cache. Avoid setting NuGetPackageRoot in
RepoLayout.props because it is already being set to the correct location
in the *.nuget.g.props files created for each project.

Fixes dotnet#14761
  • Loading branch information
sharwell committed May 10, 2024
1 parent 480401b commit 1020e14
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
15 changes: 14 additions & 1 deletion eng/common/tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,20 @@ function GetNuGetPackageCachePath() {
# 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\'
# Check NuGet.Config to see if the packages folder has been redirected https://github.com/dotnet/arcade/issues/14761
$nugetConfig = Join-Path $env:APPDATA "NuGet\NuGet.Config"
if (Test-Path -Path $nugetConfig) {
[xml]$nugetConfigXml = Get-Content $nugetConfig

# Set the NUGET_PACKAGES environment variable to match the configured globalPackagesFolder. If there is no
# global packages folder, this expression will evaluate to the empty string which will effectively leave the
# environment variable set to null.
$env:NUGET_PACKAGES = $nugetConfigXml.SelectSingleNode("//configuration/config/add[@key='globalPackagesFolder']").value
}

if ($env:NUGET_PACKAGES -eq $null) {
$env:NUGET_PACKAGES = Join-Path $env:UserProfile '.nuget\packages\'
}
} else {
$env:NUGET_PACKAGES = Join-Path $RepoRoot '.packages\'
$env:RESTORENOCACHE = $true
Expand Down
8 changes: 0 additions & 8 deletions src/Microsoft.DotNet.Arcade.Sdk/tools/RepoLayout.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
Properties describing the layout of the repo.
-->

<PropertyGroup>
<!-- 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>
</PropertyGroup>

<PropertyGroup>
<RepoRoot Condition="'$(RepoRoot)' == ''">$([MSBuild]::NormalizeDirectory('$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'global.json'))'))</RepoRoot>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
Writes a stub file to component intermediate directory.
-->

<PropertyGroup>
<ArcadeVisualStudioBuildTasksAssembly>$(NuGetPackageRoot)microsoft.dotnet.build.tasks.visualstudio\$(MicrosoftDotNetBuildTasksVisualStudioVersion)\tools\net472\Microsoft.DotNet.Build.Tasks.VisualStudio.dll</ArcadeVisualStudioBuildTasksAssembly>
</PropertyGroup>

<UsingTask TaskName="Microsoft.DotNet.Build.Tasks.VisualStudio.FinalizeInsertionVsixFile" AssemblyFile="$(ArcadeVisualStudioBuildTasksAssembly)" />

<PropertyGroup>
Expand Down
4 changes: 0 additions & 4 deletions src/Microsoft.DotNet.Arcade.Sdk/tools/VisualStudio.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. -->
<Project>

<PropertyGroup>
<ArcadeVisualStudioBuildTasksAssembly>$(NuGetPackageRoot)microsoft.dotnet.build.tasks.visualstudio\$(MicrosoftDotNetBuildTasksVisualStudioVersion)\tools\net472\Microsoft.DotNet.Build.Tasks.VisualStudio.dll</ArcadeVisualStudioBuildTasksAssembly>
</PropertyGroup>

<!-- Default settings for VSIX projects -->

<PropertyGroup>
Expand Down

0 comments on commit 1020e14

Please sign in to comment.