I have the following convention for most of my projects:
/src
/Solution.sln
/SolutionFolder
/Project1
/Project2
/etc..
/lib
A solution for Nuget 3.2 on Visual Studio 2015 is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="../lib" />
</config>
</configuration>
Using forward slash for parent folder. Save above file (nuget.config) in solution folder.
Reference is available here
One more little tidbit that I just discovered. (This may be so basic that some haven't mentioned it, but it was important for my solution.) The "packages" folder ends up in the same folder as your .sln file.
We moved our .sln file and then fixed all of the paths inside to find the various projects and voila! Our packages folder ended up where we wanted it.
In order to change the path for projects using PackageReference instead of packages.config you need to use globalPackagesFolder
From https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file
globalPackagesFolder (projects using PackageReference only)
The location of the default global packages folder. The default is %userprofile%.nuget\packages (Windows) or ~/.nuget/packages (Mac/Linux). A relative path can be used in project-specific nuget.config files. This setting is overridden by the NUGET_PACKAGES environment variable, which takes precedence.
repositoryPath (packages.config only)
The location in which to install NuGet packages instead of the default $(Solutiondir)/packages folder. A relative path can be used in project-specific nuget.config files. This setting is overridden by the NUGET_PACKAGES environment variable, which takes precedence.
<config>
<add key="globalPackagesFolder" value="c:\packageReferences" />
<add key="repositoryPath" value="c:\packagesConfig" />
</config>
I put Nuget.config next to my solution file and it worked.
this did NOT work for me:
<configuration>
<config>
<add key="repositoryPath" value="..\ExtLibs\Packages" />
</config>
...
</configuration>
this did WORK for me:
<?xml version="1.0" encoding="utf-8"?>
<settings>
<repositoryPath>..\ExtLibs\Packages</repositoryPath>
</settings>
Okay for the sake of anyone else reading this post - here is what I understand of the myriad of answers above:
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
I could not get the latest nuget (2.8.5) to find a packages folder outside of the standard location without enabling package restore. So once you enable package restore then the following should be added to the nuget.config file inside of the .nuget folder to change the location:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<config>
<add key="repositoryPath" value="..\..\Packages" />
</config>
...
</configuration>
(This is important) If you make ANY changes to the package folder location inside of the nuget.config files you must restart visual studio or close/reload the solution for the changes to take effect
nuget.config
in same directory where your solution file is, with following content:<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="packages" />
</config>
</configuration>
'packages'
will be the folder where all packages will be restored.