Change NuGet package location folder

gdfgdfg picture gdfgdfg · Dec 17, 2017 · Viewed 15.6k times · Source

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.

Answer

Leo Liu-MSFT picture Leo Liu-MSFT · Dec 18, 2017

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.