1

How can I restore a NuGet package and all of its dependencies without specifying each of them individually?

Say I have a packages.config file that is not associated with a .csproj or .sln file.

It contains one package ("PackageA") and this package has its own dependency ("PackageB").

Running nuget.exe install packages.config will install PackageA, but not PackageB.

Is there a way for nuget.exe to install PackageA AND its dependency PackageB?


Below is a reproducible example.

I have a manually generated packags.config that references Moq, a package that has two dependencies:

<?xml version="1.0" encoding="utf-8"?>
<packages>
    <package id="Moq" version="4.18.4" />
</packages>

I downloaded nuget.exe from here. When I run nuget.exe install packages.config, only Moq.4.18.4 is installed, without any of the dependencies. I see the same result when I run nuget.exe restore packages.config -PackageDirectory ..

Contrast this with running nuget.exe install moq, which WILL install Moq and all of its dependencies.


Per Microsoft's documentation on dependency resolution with packages.config, I think that the dependencies need to be explicitly specified. This suggests that I cannot manually create a packages.config file that only references "Moq" or "PackageA" for example. I could use this packages.config as input to a script that calls nuget.exe install for each package (and thus installing dependencies automatically that way), but that feels a little clunky...


More evidence suggesting I am out of luck.

Derek
  • 121
  • 6
  • `nuget restore`? – ChrisMM Mar 10 '23 at 23:31
  • No, I get the same outcome -- only PackageA – Derek Mar 10 '23 at 23:36
  • Are you sure the package / command is correct? The [docs](https://learn.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-restore), when used with a packages.config file, _Restore packages listed in the file, resolving and installing dependencies_ – ChrisMM Mar 11 '23 at 01:07
  • I've added a reproducible example that demonstrates this behavior – Derek Mar 13 '23 at 15:08

1 Answers1

1

Per the edits to my question, I was unable to find a way to restore dependencies that are NOT directly specific in a packages.config file. My advice would be to only restore from a file like this if you are ready to specify additional dependencies manually; otherwise, use nuget install for specific package targets or use a csproj file where you only need to specify the direct dependencies.

Derek
  • 121
  • 6