18

Closed

Package Restore ignores nuget.config repositoryPath setting.

description

When manually adding NuGet packages, they are downloaded to the specified directory in nuget.config <repositoryPath> setting. However the package restore functionality ignores this setting and always downloads to \packages.

Steps to reproduce:
  • in solution directory, create a file "nuget.config"
  • edit nuget.config and add:
<settings>
<repositoryPath>..\Dependencies</repositoryPath>
</settings>
  • In visual studio, right-click on Solution, and select Manage NuGet Packages
  • Install a package (any package)
  • Verify that package was downloaded to ${SolutionDir}..\Dependencies
  • delete the downloaded package in ${SolutionDir}..\Dependencies using windows explorer.
  • In Visual Studio, right-click on Solution, and Enable NuGet Package Restore
  • Rebuild solution (to trigger package restore of what you already deleted)
    *** Error occurs here: Package Restore re-downlaods the package to the default ${SolutionDir}\packages instead of ${SolutionDir}..\Dependencies
Closed Feb 4, 2013 at 11:18 PM by feiling
This is the same issue as http://nuget.codeplex.com/workitem/2921.

comments

rally25rs wrote Mar 8, 2012 at 7:59 PM

As a workaround:
  • Edit the file: ${SolutionDir}.nuget\NuGet.targets
  • Change this line to match whatever path is in the ${SolutionDir}\nuget.config:
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>

ChrisTorng wrote Mar 20, 2012 at 7:57 AM

I wish to checkin only one .nuget folder, as in Item 2003 http://nuget.codeplex.com/workitem/2003?ProjectName=nuget .
So the workaround to change NuGet.targets can only meet one solution's need.
I think it should respect each solution's repositoryPath, or I can define only one repositoryPath for all solutions in one team project.

jdstuart wrote Nov 8, 2012 at 5:56 PM

Any updates on this?

markusml wrote Nov 13, 2012 at 6:58 AM

I think the config file structure has changed. Replace the contents of the nuget.config file with:

<configuration>
<config>
<add key="repositoryPath" value="..\Dependencies" />
</config>
</configuration>

You can also put the nuget.config one folder level higher (i.e. next to your repository path) as described in the Release Notes of nuget 2.1.

Quango wrote Dec 11, 2012 at 12:42 PM

I think this is an error in the 2.1 documents, I've added a new issue:

http://nuget.codeplex.com/workitem/2900

The docs for 2.1 say it is now <config><add key="repositoryPath" ...
(see http://docs.nuget.org/docs/release-notes/nuget-2.1 )

However I've rooted about in the source code and this is not how the nuget.config file seems to be parsed, it still searches for <repositoryPath></repositoryPath> (see item 2900 for details).

deepakverma wrote Jan 2, 2013 at 9:29 PM

Actually, you should enable package restore first (instead of creating the nuget.config) and then add the settings to .nuget\nuget.config
(if .nuget folder exists it starts looking for nuget.config from there and then traversing the parent folder hierarchy)
<configuration>
<config>
<add key="repositoryPath" value="..\Dependencies" />
</config>
</configuration>
As stated in the release notes, this is the new way to specify the repositorypath and is inline with the pattern to set a key
Also, you would have to reload the solution in visual studio if you edit the config to change the path after the solution has been loaded.

jmjc95 wrote Sep 19, 2013 at 8:03 AM

I believe this is a regression recently introduce in NuGet 2.6.
in 2.5 I setup several of our solutions in VS to automatically manage references through NuGet and restore them when not found (awesome feature for CI and prevent bloating the repository with unnecessary binary files). However, for a few weeks now I noticed that both, VS2012 and VS2013preview and now RC completely ignore the value set in nuget.config. This is how my nuget.config file looks (under .nuget folder found at the solution directory level)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="..\..\lib\packages" />
</config>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>

I have tried setting the disableSourceControlIntegration value to false, no effect. I have removed that element completely, no effect either. The restore is restoring all of the references managed by Nuget to $(SolutionDir)packages.
I tried to find the variable in NuGet.Targets mentioned in one of the earlier comments, but I don't see where that variable is.
I modified this line instead:
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(SolutionDir)..\lib</PackageOutputDir>

but that has no effect either.

Help solving this issue will be greatly appreciated.