I have a solution with a packages folder checked into source control. I changed some of the projects to use a project.json file rather than packages.config for defining dependencies. The projects are all normal .csproj projects, not DNX .xproj projects. Everything seemed to be working correctly however after updating a package I noticed that the new version wasn't added to the solution's packages folder. Instead it was added to NuGet's new shared packages folder in the user profile folder.
So the question is, how do I get NuGet to use the solution's packages folder rather than the shared folder?
Approaches I've tried so far without success:
- Adding
global.jsonfile in the solution folder specifying"packages": "packages" - Setting
<add key="disableSourceControlIntegration" value="false" />in.nuget\nuget.config
NuGet 3.2 added support for specifying the shared global packages folder using an environment variable,
NUGET_PACKAGES. You can set the full path to an alternative global packages folder, however I discovered that if you simply set the variable to "packages" then the NuGet tools in Visual Studio will treat it as a relative path under your solution folder. That allowed me to install and restore NuGet packages using the solution'spackagesfolder.Unfortunately building projects then gave me errors in
Microsoft.NuGet.targets, unable to locate NuGet packages. TheNugetPackagesDirectoryproperty in msbuild doesn't seem to getting set. To work around this I added the following lines in to theC:\Program Files (x86)\MSBuild\Microsoft\NuGet\Microsoft.NuGet.propsfile:This will affect all solutions on the machine so an alternative would be to add those same lines in each project file or into a custom
propsfile in the solution which you import into each project. This may also be needed for build servers too.Although this works, the drawback is that the packages folder has a different structure,
packages\<package_name>\<version>\compared topackages\<package_name>.<version>\, and old or unused versions of packages aren't deleted after they're updated or uninstalled. Manually clearing the packages directory and then restoring required packages after any changes will achieve the same thing.Personally this feels really hacky as it requires setting global settings for something which should be set on a per solution basis. NuGet is going to be updated at some point to support per solution package directories with
project.jsonbut in the meantime this you can use the above work around, or just stick withpackages.configfor the time being.