DEV Community

tombohub
tombohub

Posted on

How to change default Nuget packages folder on Windows

The default folder where C# solutions will save the nuget packages is %UserProfile%\.nuget\packages .

To change to different one there are 2 options:

Add config to NuGet.config file:

File locations is %APPDATA%\NuGet\NuGet.config for user specific, or %ProgramData%\NuGet\NuGet.config if it's global installation.

Add globalPackagesFolder settings. I was confused by repositoryPath after googling which is different thing! Do not be confused, use globalPackagesFolder setting!

You add settings in config section like this:

  <config>
    <add key="globalPackagesFolder" value="D:\YourFolderPath" />
  </config>
Enter fullscreen mode Exit fullscreen mode

so whole config file should look something like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageManagement>
    <add key="format" value="0" />
    <add key="disabled" value="True" />
  </packageManagement>
  <config>
    <add key="globalPackagesFolder" value="D:\YourFolderPath" />
  </config>
</configuration>
Enter fullscreen mode Exit fullscreen mode

Adding NUGET_PACKAGES env variable:

Google in order to see how to do it: google search

After that run command in terminal dotnet nuget locals -l all
and you should see your new folder in global-packages:

http-cache: C:\Users\ME\AppData\Local\NuGet\v3-cache
global-packages: D:\YourFolderPath
temp: C:\Users\ME\AppData\Local\Temp\NuGetScratch
plugins-cache: C:\Users\ME\AppData\Local\NuGet\plugins-cache
Enter fullscreen mode Exit fullscreen mode

Top comments (0)