I have the following convention for most of my projects:
/src
/Solution.sln
/SolutionFolder
/Project1
/Project2
/etc..
/lib
The solution proposed in release notes for 2.1 doesn't work out-of-the-box. They forgot to mention that there is code:
internal string ResolveInstallPath()
{
if (!string.IsNullOrEmpty(this.OutputDirectory))
{
return this.OutputDirectory;
}
ISettings settings = this._configSettings;
...
}
which prevents it from working. To fix this you need to modify your NuGet.targets file and remove 'OutputDirectory' parameter:
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch)</RestoreCommand>
So now, if you add 'repositoryPath' config somewhere in NuGet.config (see the release notes for a description of valid places to put the config files), it will restore all packages into single location, but... Your .csproj still contains hints to assemblies written as relative paths...
I still don't understand why they went hard way instead of changing PackageManager so it would add hint paths relative to PackagesDir. That's the way I do manually to have different package locations locally (on my desktop) and on build agent.
<Reference Include="Autofac.Configuration, Version=2.6.3.862, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>$(PackagesDir)\Autofac.2.6.3.862\lib\NET40\Autofac.Configuration.dll</HintPath>
</Reference>
For .NET Core projects and Visual Studio 2017 I was able to restore all packages to relative path by providing this configuration:
<configuration>
<config>
<add key="globalPackagesFolder" value="lib" />
</config>
...
</configuration>
Based on my experience the lib folder was created on the same level where Nuget.config was found, no matter where sln file was. I tested and the behavior is same for command line dotnet restore, and Visual Studio 2017 rebuild
Just updating with Nuget 2.8.3. To change the location of installed packages , I enabled package restore from right clicking solution. Edited NuGet.Config and added these lines :
<config>
<add key="repositorypath" value="..\Core\Packages" />
</config>
Then rebuilt the solution, it downloaded all packages to my desired folder and updated references automatically.