how to get all nuget dependencies for offline installation

20,897

Solution 1

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.

Solution 2

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

Solution 3

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

Solution 4

A little late to the discussion here but I just ran into the same issue. I work with a medium size software development shop that works offline. Many new NuGet packages have very large dependency trees. Trying to walk the tree manually and download all required packages was very cumbersome. In the end, I wrote the NuGet Dependency Downloader. With it you give a package ID, optionally a version, and choose if you want to allow pre-release packages. After you click "Start" it will pull down the listed package and any dependencies it needs to run. As an example, when I put in "Microsoft.AspNet.Mvc" and selected "pre-release", this tool brought down 158 packages for MVC 6.0 RC1. Hopefully this will help those working in an offline environment.

https://github.com/StuffOfInterest/NuGetDependencyDownloader

Solution 5

Execute following command in your project path.

    dotnet restore --packages <Dependencies Output Dir> <Project Path>

Ref:dotnet restore

Share:
20,897
Colleen MacRay
Author by

Colleen MacRay

Updated on March 03, 2022

Comments

  • Colleen MacRay
    Colleen MacRay about 2 years

    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.

  • CSCoder
    CSCoder about 6 years
    Not sure why no one has upvoted this yet but this is exactly what i needed. No third party software solution! Thanks
  • Igand
    Igand almost 6 years
    Thanks! You mean run from simple consele, right? Then it works even without -OutputDirectory option, directory with package just gets downloaded into directory with nuget.exe. I use it like this "nuget install NullGuard.Fody -Version 1.8.0", where the name and version is simply copy pasted from info on nuget.org for given package.
  • Adrian Sanguineti
    Adrian Sanguineti almost 6 years
    @Igand, you're absolutely correct that the -OutputDirectory is not needed. I think I must of confused myself when I was searching for a solution, and must have mixed up with another issue. In anycase, since I needed to upload the downloaded packages to a private feed, the -OutputDirectory switch helped me organise all the downloaded packages and dependencies into their own folder, making it clear which each package required on its own.
  • PKV
    PKV over 5 years
    how should I restore nuget for your project :D
  • PKV
    PKV over 5 years
    I did it, manual download, not many. Thanks, I will check it out.
  • colidyre
    colidyre about 4 years
    While this code snippet may be the solution, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.
  • Scott Hutchinson
    Scott Hutchinson almost 4 years
    How does this help?
  • GidiBloke
    GidiBloke about 3 years
    Got the packages, not the dependencies. Not very useful
  • Zar Shardan
    Zar Shardan about 3 years
    If dependencies are not downloading, make sure you specify the -Framework flag (ex: -Framework netstandard2.0)
  • ruffin
    ruffin about 2 years
    I didn't find Cache, but do see a directory with "v3-cache at the end of the path replacing it. It's full of .DAT files, not .nupkg. Not sure if the answer needs an update or I'm in the wrong place. EDIT: Looks like they're in C:\Users\yourName\.nuget\packages now?
  • Matt Ward
    Matt Ward about 2 years
    Yeah, this answer is quite old. The NuGet packages moved to another directory. docs.microsoft.com/en-us/nuget/Consume-Packages/…
  • ruffin
    ruffin about 2 years
    Absolutely the right idea, though, imo. I copied the folders for the nugets I needed from ...\.nuget\packages, copied to a new dir on the "offline" workstation, set up a "local" nuget source in VS by pointing to the directory where I copied them, and *poof*, success. +1!