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 at 10:18 PM by feiling
This is the same issue as http://nuget.codeplex.com/workitem/2921.

comments

rally25rs wrote Mar 8, 2012 at 6: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 6: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 4:56 PM

Any updates on this?

markusml wrote Nov 13, 2012 at 5: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 11:42 AM

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 at 8: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.