how to get all nuget dependencies for offline installation

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


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

On the computer with internet access the NuGet packages (.nupkg) should be in the local machine cache. On Windows this is in the directory similar to:

C:\Users\YourUsername\.nuget\packages

So you should be able to copy the .nupkg files from there to the computer without internet access. I would create a directory on that computer and setup a new package source pointing to that directory. Alternatively you could copy the .nupkg files to the local machine cache, just be aware there is a limit of 200 NuGet packages in the cache. Then you can create a package source pointing to the cache.