Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download nuget packages to well-known location #11056

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

brettfo
Copy link
Contributor

@brettfo brettfo commented Dec 5, 2024

NuGet package analysis needs to download the packages to examine the dependencies. This was previously done with $TMP but that could result in duplicate package downloads, using extra network bandwidth as well as disk space.

In the worst case scenario, the initial package would be downloaded to 2 places on disk and the updated package would be downloaded to 3. E.g., if updating Newtonsoft.Json from 11.0.1 to 13.0.1 there would be 1 copy of Newtonsoft.Json/11.0.1 in $TMP and 1 copy in the global package cache. There would then be 2 copies of Newtonsoft.Json/13.0.1 in $TMP and 1 in the global package cache. With these changes there is now only 1 copy of 11.0.1 and 1 copy of 13.0.1, both in the global package cache. Assuming a similar size between different versions of the same package, we're now downloading only 40% of what we were before.

The behavior now is to use this well-known global package cache location as the download location. This meant that the unit tests needed to be updated to always have their own global package cache so they didn't pollute each other. To make this more consistent, the TemporaryDirectory class was modified to also set the appropriate NUGET_* environment variables. Now as long as a test or test helper has using var tempDirectory = new TemporaryDirectory(); that test will get its own global package cache location.

@brettfo brettfo requested a review from a team as a code owner December 5, 2024 01:30
@github-actions github-actions bot added the L: dotnet:nuget NuGet packages via nuget or dotnet label Dec 5, 2024
@@ -207,6 +207,21 @@ internal static PackageReaders ReadPackage(string tempPackagePath)
return null;
}

internal static string GetTempPackagePath(PackageIdentity package, NuGetContext context)
=> Path.Combine(context.TempPackageDirectory, package.Id + "." + package.Version + ".nupkg");
internal static string GetPackagePath(PackageIdentity package, NuGetContext context)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is the real fix. All other changes are to make the unit tests more consistent.

@brettfo brettfo force-pushed the dev/brettfo/nuget-download-location branch from 6e59a13 to fdf8606 Compare December 5, 2024 17:31
@sebasgomez238
Copy link
Contributor

Is this expected to make execution times a lot faster or are the performance gains minimal?

@brettfo
Copy link
Contributor Author

brettfo commented Dec 5, 2024

It will help somewhat since downloads won't be repeated, but I don't have any concrete numbers.

@randhircs randhircs force-pushed the dev/brettfo/nuget-download-location branch from fdf8606 to 3fcf80d Compare December 5, 2024 22:28
@randhircs randhircs merged commit fa7a4d0 into main Dec 5, 2024
70 checks passed
@randhircs randhircs deleted the dev/brettfo/nuget-download-location branch December 5, 2024 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: dotnet:nuget NuGet packages via nuget or dotnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants