Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get all nuget dependencies for offline installation

I two computers, one with internet connection and the other one without.

I want to install a Nuget package (Nuget.server) with all its dependencies on the offline computer. Unfortunately it is not possible just to download the package itself and I have to download all dependencies manually and there are dozens of them.

How can I create a package on the computer with internet connection that contains all dependencies?

Thanks.

like image 302
Colleen MacRay Avatar asked Jul 13 '14 16:07

Colleen MacRay


People also ask

Does NuGet automatically install dependencies?

Install NuGet packages without dependenciesBy default, when installing NuGet packages, corresponding package dependencies will also be installed in your project. To avoid the installation of dependent packages, choose the Ignore Dependencies option in the Dependency behavior drop-down in NuGet Package Manager.

How do I download missing NuGet packages?

Enable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.

Does NuGet package include dependencies?

Any time a package is installed or reinstalled, which includes being installed as part of a restore process, NuGet also installs any additional packages on which that first package depends. Those immediate dependencies might then also have dependencies on their own, which can continue to an arbitrary depth.


2 Answers

I just went through the pain of this and wanted to find a solution using only the NuGet CLI. Turns out it's pretty simple really:

> nuget.exe install <PACKAGENAME> -OutputDirectory <OUTPUTDIR>

The key is the -OutputDirectory switch which makes the CLI install the specified package into a directory that doesn't have a project file in it. Running this command will download the package and all of its dependencies into the output directory, with each package put into a separate sub-folder. You can then grab all of the .nupkg from the output directory and do whatever you need to do with them.

Update: As Igand points out in the comments, the -OutputDirectory switch is not actually required. If omitted nuget.exe will just download into the current folder. Still best to not download it into a folder with a project file in it (unless that is what you're after).

like image 188
Adrian Sanguineti Avatar answered Oct 10 '22 10:10

Adrian Sanguineti


I had a similar need, so I created NuSave.

Cache a single NuGet package with dependencies

nusave cache package "[email protected]" --targetFrameworks "[email protected],[email protected]" --cacheDir "C:\path\to\my-local-feed"

Cache multiple NuGet packages from a .csproj file

nusave cache csproj "C:\path\to\project.csproj" --cacheDir "C:\path\to\my-local-feed"

Cache multiple NuGet packages from an .sln file

nusave cache sln "C:\path\to\solution.sln" --cacheDir "C:\path\to\my-local-feed"

Restore & build a solution offline using my local cache

cd C:\path\to\my-solution
dotnet restore --packages C:\path\to\my-local-feed
dotnet build --no-restore
like image 43
Elias Avatar answered Oct 10 '22 10:10

Elias