I have some .nupkg files from a C# book. How can I install them?
https://i.stack.imgur.com/RMgIm.jpg
Menu Tools → Options → Package Manager
https://i.stack.imgur.com/BgbB0.png
Give a name and folder location. Click OK. Drop your NuGet package files in that folder.
Go to your Project in Solution Explorer, right click and select "Manage NuGet Packages". Select your new package source.
https://i.stack.imgur.com/jOthh.png
Here is the documentation.
You can also use the Package Manager Console and invoke the Install-Package
cmdlet by specifying the path to the directory that contains the package file in the -Source
parameter:
Install-Package SomePackage -Source C:\PathToThePackageDir\
-Source
option is available in nuget.exe as well. For example: nuget install SomePackage -Source C:\PathToThePackageDir
For .nupkg files I like to use:
Install-Package C:\Path\To\Some\File.nupkg
.nupkg
under the same directory every other packages were stored)
For Visual Studio 2017 and its new .csproj format
You can no longer just use Install-Package to point to a local file. (That's likely because the PackageReference
element doesn't support file paths; it only allows you to specify the package's Id.)
You first have to tell Visual Studio about the location of your package, and then you can add it to a project. What most people do is go into the NuGet Package Manager and add the local folder as a source (menu Tools → Options → NuGet Package Manager → Package Sources). But that means your dependency's location isn't committed (to version-control) with the rest of your codebase.
Local NuGet packages using a relative path
This will add a package source that only applies to a specific solution, and you can use relative paths.
You need to create a nuget.config
file in the same directory as your .sln
file. Configure the file with the package source(s) you want. When you next open the solution in Visual Studio 2017, any .nupkg files from those source folders will be available. (You'll see the source(s) listed in the Package Manager, and you'll find the packages on the "Browse" tab when you're managing packages for a project.)
Here's an example nuget.config
to get you started:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyLocalSharedSource" value="..\..\..\some\folder" />
</packageSources>
</configuration>
Backstory
My use case for this functionality is that I have multiple instances of a single code repository on my machine. There's a shared library within the codebase that's published/deployed as a .nupkg file. This approach allows the various dependent solutions throughout our codebase to use the package within the same repository instance. Also, someone with a fresh install of Visual Studio 2017 can just checkout the code wherever they want, and the dependent solutions will successfully restore and build.
-Source
argument to Update-Package
and it worked fine. Maybe something to do specifically with the Install-Package
command?
Add the files to a folder called LocalPackages next to you solution (it doesn't have to be called that, but adjust the xml in the following step accordingly) Create a file called NuGet.config next to your solution file with the following contents
Now your packages should appear in the browser, or be installable using Install-Package
If you have a .nupkg file and just need the .dll file all you have to do is change the extension to .zip and find the lib directory.
Just to give an update, there are minor changes for Visual Studio 2015 users.
To use or install package manually, go to Tools -> Options -> NuGet Package Manager -> Package Sources
Click the Add button, choose the Source, and don't forget to click "Update" as it will update the folder location for your packages, edit your desired Name of your package source if you want:
https://i.stack.imgur.com/d6Bfk.jpg
To choose your added package, right click your solution and select "Manage Nuget Packages"
The drop down list is on the right and choose Browse to browse your packages that you specified on your folder source. If there is no nuget package on that folder source, this will be empty:
https://i.stack.imgur.com/HCFDE.jpg
On Linux, with NuGet CLI, the commands are similar. To install my.nupkg, run
nuget add -Source some/directory my.nupkg
Then run dotnet restore
from that directory
dotnet restore --source some/directory Project.sln
or add that directory as a NuGet source
nuget sources Add -Name MySource -Source some/directory
and then tell msbuild
to use that directory with /p:RestoreAdditionalSources=MySource
or /p:RestoreSources=MySource
. The second switch will disable all other sources, which is good for offline scenarios, for example.
Recently I want to install squirrel.windows
, I tried Install-Package squirrel.windows -Version 2.0.1
from https://www.nuget.org/packages/squirrel.windows/, but it failed with some errors. So I downloaded squirrel.windows.2.0.1.nupkg
and save it in D:\Downloads\
, then I can install it success via Install-Package squirrel.windows -verbose -Source D:\Downloads\ -Scope CurrentUser -SkipDependencies
in powershell.
pack your library using one of the 3 options:
Visual Studio (csproj > Properties > Package > Tick "Generate NuGet Package on Build". Then Build the solution)
dotnet CLI (in command prompt in project folder: dotnet build, then dotnet pack commands)
NuGet CLI (in command prompt in project folder: dotnet build, then nuget pack command)
add generated package (in project folder bin > Debug (or Release) > *.nupkg file) to the offline feed (default location in VS2019 is C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\) using nuget add command In VS, Manage NuGet Packages > Top-right: Change Package source to Microsoft Visual Studio Online Packages.
Detailed instruction can be found here or on yt
Success story sharing