devhome icon indicating copy to clipboard operation
devhome copied to clipboard

Use user NuGet.config, not NUGET_PACKAGES environment variable

Open nguerrera opened this issue 11 months ago • 5 comments
trafficstars

Dev Home version

0.1901.687.0

Windows build number

No response

Other software

NuGet - all versions

Steps to reproduce the bug

  1. Open Dev Home app
  2. Windows Customization
  3. DevDrive Insights
  4. NuGet Cache (dotnet)
  5. Make the change

Expected result

It changes the global nuget package folder using %APPDATA%\NuGet\NuGet.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
+  <config>
+    <add key="globalPackagesFolder" value="D:\packages\NuGet\cache" />
+  </config>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

Actual result

It changes the package folder using NUGET_PACKAGES environment variable.

The problem with this is that it wins over a repo-local NuGet.config. This is documented and by-design in NuGet.

https://github.com/NuGet/Home/issues/4810#issuecomment-347665093 https://learn.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders

The environment variable takes precedence over the configuration setting.

I lost nearly a whole day finding this out the hard way.

There are many examples of repos that set globalPackagesFolder in repo-local config and customers could easily get bit too:

https://github.com/search?q=globalPackagesFolder+path%3A**%2Fnuget.config&type=code&ref=advsearch

The documentation should also be fixed here:

https://learn.microsoft.com/en-us/windows/dev-drive/#storing-package-cache-on-dev-drive https://github.com/MicrosoftDocs/windows-dev-docs/issues/5236

Included System Information

No response

Included Extensions Information

No response

nguerrera avatar Dec 05 '24 18:12 nguerrera

cc @nkolev92

nguerrera avatar Dec 05 '24 18:12 nguerrera

@nguerrera as done just this move and now reading your issue here, please explain this to me (kind of beginner, not done much more with nuget than the visual studio nuget manager (not console) I recognized more and more my device is getting slower while learning winUI which makes me create new projects, but dont think some CI is really cleaning up unneded stuff... and when seeing two places with same things, this was a sense making step to move the .nuget/packages folder from c: to devdrive...

DevTKSS avatar Dec 11 '24 18:12 DevTKSS

@DevTKSS This issue is about how to move nuget packages to dev drive. It is not about saying that they shouldn't be moved to dev drive. It is better to use the nuget config file than the NUGET_PACKAGES environment variable for the reasons I outlined in the issue.

nguerrera avatar Dec 19 '24 22:12 nguerrera

Yeah, I'm not sure I follow the reason too. I recently moved the cache too. I had the idea that a NuGet.config file was per-project or per-solution? So, if you have several repos, doesn't that mean you'd have to set this for every one?

Jay-o-Way avatar Mar 25 '25 11:03 Jay-o-Way

@Jay-o-Way No, it is more nuanced than this. See https://learn.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior#how-settings-are-applied

The key thing is that the local > user > machine config precedence applies on a per-setting basis. For example, as long as a local nuget.config doesn't say anything about globalPackagesFolder (common case), then the globalPackagesFolder in the user nuget.config will still apply. So it would be reasonable and better for Dev Home to change user nuget.config as I outlined in expected result.

nguerrera avatar Mar 25 '25 15:03 nguerrera