Is it possible to change the location of C:\Users\Myaccount\.nuget folder to another folder in drive D: ?
I need to empty some space for my C: drive.
Table of Contents
The default folder where C# solutions will save the nuget packages is %UserProfile%\.nuget\packages .
To change to different one there are 2 options:
Listing global packages,Viewing folder locations
output
There are multiple nuget packages read in the following order:
First the NuGetDefaults.Config file. You will find this in %ProgramFiles(x86)%\NuGet\Config.
The computer-level file.
The user-level file. You will find this in %APPDATA%\NuGet\nuget.config.
Any file named nuget.config beginning from the root of your drive up to the directory where nuget.exe is called.
The config file you specify in the -configfile option when calling nuget.exe
https://siderite.dev/blog/setting-nuget-package-folder-location.html/
There are two ways of configuring NuGet packages for your projects:
a packages.config file
PackageReference elements in your .csproj file
There are two locations for the nuget.config file: in a .nuget folder inside your solution folder and directly in the solution folder (or any of its parent folders)
The location that is accepted by the latest versions of NuGet is directly in the solution folder
Sometimes you need to restart Visual Studio for the change in nuget.config files to considered
The path you specify is relative to the nuget.config file, no matter where it is
By default, Visual Studio uses global Nuget.config located at path C:\Users\yourusername\AppData\Roaming\NuGet\Nuget.config
change the location of C:\Users\Myaccount\.nuget folder to another folder in drive D:
f you want to change the location of NuGet packages from drive C to D, please try the following:
option 1. Using the NUGET_PACKAGES environment variable:
or
option 2. Please add the following configuration in a nuget.config file(C:\Users\xxx\AppData\Roaming\NuGet):
https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file#config-section
you will have to edit the Nuget.config file.
In Windows 10, this file is in the path:
C:\Users\YouUser\AppData\Roaming\NuGet.
old
new
https://learn.microsoft.com/zh-cn/nuget/reference/nuget-config-file
Managing the global packages, cache, and temp folders
Clearing local folders
Setting the NuGet package folder location for Visual Studio solutions
https://siderite.dev/blog/setting-nuget-package-folder-location.html/
https://dev.to/tombohub/how-to-change-default-nuget-packages-folder-on-windows-51hb