Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change NuGet package location folder

I want to change NuGet package folder, but it does not change it. What I do is creating file nuget.config:

<configuration>
    <config>
        <add key="repositoryPath" value="C:\projects\" />
    </config>
</configuration>

I added this file in the solution folder (in same folder where is .sln file) or in the project folder and after that restart VS, but nothing happen. I am using Visual Studio 2017 Community.

like image 249
gdfgdfg Avatar asked Dec 17 '17 22:12

gdfgdfg


People also ask

Where is NuGet Packages folder?

The location of the default global packages folder. The default is %userprofile%\. nuget\packages (Windows) or ~/. nuget/packages (Mac/Linux).

How do I store NuGet packages locally?

Enable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.

Where are NuGet packages cached locally?

Well, remember that NuGet caches the packages it downloads on your local hard drive. My cache was located at C:\Users\scottha\AppData\Local\NuGet\Cache. You can add that cache folder as a NuGet Source by going to Options | Package Manager | Package Sources.

How to change the NuGet packager folder?

To change the nuget packager folder, you can you can set "NUGET_PACKAGES" environment variable. Just Set "NUGET_PACKAGES" = "c:\teampackages". Or you can place a NuGet.Config file next to the solution with the following content:

Where does the NuGet config file go?

The nuget.config file in the .nuget folder is relative to that folder. This is important because if your new folder is something like '../Packages' that will put it where it always goes out of the box. As @bruce14 states you must do '../../Packages' instead

How do I view folder locations in NuGet?

( package-cache is used in NuGet 2.x and appears with NuGet 3.5 and earlier.) You can also view folder locations using the dotnet nuget locals command:

What is the NuGet global package cache?

One of the improvements that were introduced to NuGet a few years ago was the introduction of a global package cache. Instead of having a copy of every nuget package inside your project folder, all nuget packages are downloaded and stored once on a central location on your file system.


1 Answers

Change NuGet package location folder

Depending on what sort of project you are using this setting may or may not be successfully to change NuGet packager folder.

If you are using a .NET Framework project that has a packages.config file then this setting will change the nuget package folder to C:\projects\.

But if you are using a project.json file, then this setting will not successful. Because project.json project doesn't support repositoryPath config.

To change the nuget packager folder, you can you can set "NUGET_PACKAGES" environment variable. Just Set "NUGET_PACKAGES" = "c:\teampackages". Or you can place a NuGet.Config file next to the solution with the following content:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
    <config>
      <add key="globalPackagesFolder" value=".\packages" />
    </config>
</configuration>

For the detail info, you can refer to this thread:

Dotnet restore does not honour nuget.config 'repositoryPath'.

Update:

I noticed that you are creating Xamarin.Forms project with Visual Studio Community 2017, the reference should be PackageReference, for this sort of project, you should use add below code to the .csproj file:

<PropertyGroup>
  <RestorePackagesPath>D:\Test\packages</RestorePackagesPath>
</PropertyGroup>

Then restart Visual Studio, VS/NuGet will restore nuget packages to the D:\Test\packages, it works fine on my side, you can check my test sample:

enter image description here

Hope this helps.

like image 156
Leo Liu-MSFT Avatar answered Oct 19 '22 23:10

Leo Liu-MSFT