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.
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.