how to get all nuget dependencies for offline installation
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
Colleen MacRay
Updated on March 03, 2022Comments
-
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 about 6 yearsNot sure why no one has upvoted this yet but this is exactly what i needed. No third party software solution! Thanks
-
Igand almost 6 yearsThanks! 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 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 over 5 yearshow should I restore nuget for your project :D
-
PKV over 5 yearsI did it, manual download, not many. Thanks, I will check it out.
-
colidyre about 4 yearsWhile 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 almost 4 yearsHow does this help?
-
GidiBloke about 3 yearsGot the packages, not the dependencies. Not very useful
-
Zar Shardan about 3 yearsIf dependencies are not downloading, make sure you specify the -Framework flag (ex: -Framework netstandard2.0)
-
ruffin about 2 yearsI 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 inC:\Users\yourName\.nuget\packages
now? -
Matt Ward about 2 yearsYeah, this answer is quite old. The NuGet packages moved to another directory. docs.microsoft.com/en-us/nuget/Consume-Packages/…
-
ruffin about 2 yearsAbsolutely 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!