605

I have some .nupkg files from a C# book. How can I install them?

Can't see my packages

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tom
  • 15,781
  • 14
  • 69
  • 111

10 Answers10

596

Menu ToolsOptionsPackage Manager

Enter image description here

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.

Enter image description here

Here is the documentation.

Cullub
  • 2,901
  • 3
  • 30
  • 47
Shyju
  • 214,206
  • 104
  • 411
  • 497
  • 28
    Actually, I have done step 1 a few times. But my package is not showing up in step 2, when I open up to view Installed packages, Updates or Recent packages. – Tom Apr 20 '12 at 04:20
  • 2
    On my screen, I only have "All" under "Installed packages" not the "NuGet offical package source", not my custom "newNuget", they are missing. – Tom Apr 20 '12 at 04:22
  • which version of VS you are using ? do you have an updated version of nuget ? – Shyju Apr 20 '12 at 04:23
  • 1
    I am using vs2010. Trying to download and install latest nuget from their homepage just now. Download click next next...then error...M$ as expected, there is a link of known issues, checked that, says signature mismatch then I need to uninstall the existing nuget and it is easy fix. fine, do that. When I restart computer and do install again, same error comes back, signature mismatch... so now I am stuck with the old version gone, new version doesn't want to install. – Tom Apr 20 '12 at 05:03
  • Install Error : VSIXInstaller.SignatureMismatchException: The signature on the update version of 'NuGet Package Manager' does not match the signature on the installed version. Therefore, Extension Manager cannot install the update. at VSIXInstaller.Common.VerifyMatchingExtensionSignatures(IInstalledExtension installedExtension, IInstallableExtension updateExtension) at VSIXInstaller.InstallProgressPage.BeginInstallVSIX(SupportedVSSKU targetAppID) – Tom Apr 20 '12 at 05:03
  • 2
    Problem fixed. I uninstalled nuget from windows -> control panel. It didn't work that way. I needed to start up VS and go into Tools->Extension Manager ... then hit uninstall nuget from there. Restarted VS. Then went to install nuget again, it worked. Now, the local nupkg files are showing up, too (edit: they are in the Online tab, not the Installed tab, my mistake in the picture I post). Thanks for the help :) – Tom Apr 20 '12 at 05:23
  • I have the same problem with VS2010. Oddly, if I click the "Settings" button in the lower left, I see the folder that I added listed under "Available package sources", with its checkbox checked. – Buggieboy Sep 24 '14 at 14:40
  • I tried this in Visual Studio 2015 and with Entity Framework 6.0.1 (which has NO dependencies on other packages). The NuGet manager still wanted to go online, although I had chosen to install the local package. For me, this didn't work, so unzipped the package and just used the DLLs. Just look at the answer of "user3199610" in this post. – Michael Sep 28 '15 at 09:18
  • in vs2015 I cannot add new sources – John Demetriou Apr 08 '16 at 11:23
  • for some reason only with the config file – John Demetriou Apr 08 '16 at 11:23
  • 1
    I don't have enough reputation to comment yet - but to answer Michael in the accepted answer comments about VS2015 still wanting to go online. I had the same issue, but in the options, if you untick all the online sources it works for the offline ones. [nuget Options pic](http://i.stack.imgur.com/2ErXt.jpg) – Mick m Mar 16 '16 at 12:29
  • Useful! I was wondering why VS 2015 was not installing my local .nupkg. Thanks for this – afaolek Mar 20 '16 at 21:44
  • I would like to add using right click on the solution name -> Restore nuget package will take the added local sources – GaelSa Aug 03 '16 at 08:22
  • 2
    Dont forget to change Package source from right side near the gear icon. you package will show with the name you sepecified in the previous window. thanks – MindRoasterMir Jan 06 '19 at 09:48
  • If the package is not showing up and it's not fully released, try checking *include prerelease*. – Bamdad Dec 21 '21 at 15:19
368

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\
Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154
  • 2
    can i do something like that with the command line tool also? – Poul K. Sørensen Oct 09 '13 at 13:11
  • 8
    Yes. The `-Source` option is available in [nuget.exe](http://docs.nuget.org/docs/reference/command-line-reference) as well. For example: `nuget install SomePackage -Source C:\PathToThePackageDir` – Enrico Campidoglio Oct 09 '13 at 13:29
  • 1
    was a little quick, sorry. What i wanted was the other way around. I would love to use the nuget command line to install dlls into bin folder on a cms site. But i found out reading online that it cant install, only pull down the dlls. – Poul K. Sørensen Oct 09 '13 at 13:30
  • 20
    You might need to specify the -IncludePrerelease flag as well. Otherwise, if the package version has a dash-suffix (e.g "-beta1"), Install-Package won't find it. – Jeff Sharp Mar 02 '14 at 21:49
  • 11
    This is a much more direct answer than the accepted one. Thanks for the info! – David Peters Apr 02 '14 at 19:12
  • Please note that there is no need to specify the version number for `SomePackage` even if the local *.nupkg file have version numbers in the file name. – Felix Aug 26 '17 at 13:14
  • 4
    Doesn't work for VS 2017, see f.ex. answer by @Granger. – RenniePet Mar 04 '18 at 23:47
  • I am getting error after executing this command (Unable to find package 'packagename'). I first downloaded the nuget package then extract it into local drive by .zip then provided -source part of .nuspec file and used package name from metadata tag. correct me if i am missing something – Niraj Trivedi May 24 '18 at 01:49
  • 1
    @NirajTrivedi You don't have to extract the contents of the NuGet package – the directory you specify with `-Source` should contain the NuGet package file itself (_*.nupkg_). – Enrico Campidoglio May 24 '18 at 13:49
  • @JeffSharp This was really crucial for me. Moreover, in the UI, one may need to press "Include Prerelease" in the same circumstances one needs to provide that flag on the command line. – bchurchill Sep 28 '18 at 04:16
179

For .nupkg files I like to use:

Install-Package C:\Path\To\Some\File.nupkg
Felix Alcala
  • 2,837
  • 3
  • 27
  • 31
  • 8
    Agree. And worth mentioning that only absolute paths work – Sebastian J. Oct 25 '17 at 05:46
  • 8
    Doesn't work for VS 2017, see f.ex. answer by @Granger. – RenniePet Mar 04 '18 at 23:46
  • 2
    @RenniePet that worked for me in VS2017 (but I had already placed my `.nupkg` under the same directory every other packages were stored) – Rafalon Mar 26 '18 at 14:08
  • 2
    It is not working for me, I am using VS2013 Version 12.0.21..5 and Nuget package manager 2.12.0.817 :( – Niraj Trivedi May 24 '18 at 02:25
  • 1
    I do not get this to work with the nuget.exe cli tool. It tries to find the package using the feeds in the nuget config (GET https://nuget.COMPANY.nl/nuget/NuGet/FindPackagesById()?id='C:%5CProgram Files (x86)...) – Kevin Jun 06 '18 at 10:01
  • 1
    Worked for me. Was able to import CodeView (java stuff) Nuget package and build and run a simple app. – David Jones Sep 29 '18 at 12:49
  • For me this didn't work as well. I got an error telling me `The 'Source' parameter is not respected for the transitive package management based project(s)`. This doesn't seem to be fixed yet: https://github.com/NuGet/Home/issues/7189 – FranzHuber23 Jul 16 '19 at 11:33
  • 1
    This is the real answer! Because, if you need to install just one package once from a certain location, this is how you do it. No need for the overhead like in the accepted answer. – Legends Sep 30 '19 at 17:32
  • 1
    Worked on VS2019. Thank you very much. – CareTaker22 Feb 22 '21 at 19:24
  • 1
    "Install-Package' is not recognized as an internal or external command, operable program or batch file." – Enrico Oct 20 '21 at 08:37
  • 2
    Maybe someone needs to point out that this is a PowerShell command. @Enrico – uceumern Apr 13 '22 at 10:47
106

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 ToolsOptionsNuGet Package ManagerPackage 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Granger
  • 3,639
  • 4
  • 36
  • 34
  • I am using VS 2017 and haven't run into this problem. I just passed the `-Source` argument to `Update-Package` and it worked fine. Maybe something to do specifically with the `Install-Package` command? – Greg Burghardt Jun 20 '19 at 15:04
  • Just wanting to point out that this works great on VS 2019, and equally well in DevOps pipelines. Had to do this to be able to use FastReports in our solution that's built & deployed with CI/CD. HOWEVER, the nuget.config had to also have the official repo URL, AND use the Nuget Restore task, NOT DotNetCLI restore, because that creates a copy of the nuget.config so your relative path no longer works. – James Love Jan 28 '22 at 10:39
65
  1. 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)
  2. Create a file called NuGet.config next to your solution file with the following contents

    <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        <packageSources>
          <add key="LocalPackages" value="./LocalPackages" />
        </packageSources>
        <activePackageSource>
          <!-- this tells that all of them are active -->
          <add key="All" value="(Aggregate source)" />
        </activePackageSource>
     </configuration>
    
  3. If the solution is open in Visual Studio, close it, then re-open it.

Now your packages should appear in the browser, or be installable using Install-Package

Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
Samuel Jack
  • 32,712
  • 16
  • 118
  • 155
  • 1
    This may just be because I have a package with the same name as one on the Nuget repository, but I needed to use the Package Manager Console and select the package source as LocalPackages before running Install-Package. – Luke Sep 05 '18 at 06:12
60

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.

Marlon Cristian
  • 633
  • 5
  • 5
  • 3
    if you treat it as a zip file, then files having space in the file name will be extracted with % (replacing the spaces). To avoid this install using NuGet. – Rahatur Apr 09 '16 at 06:10
  • 6
    Actually, you do not even need to rename the extension. Just right-click the file, and then choose Open with, and find an application that can open the .zip file, and the .nupkg file can be opened, and then you can extract the needed dll file to your designated folder. – jyao Dec 15 '17 at 19:07
  • 2
    Best solution I need – Leo Nguyen Sep 08 '18 at 08:22
23

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:

enter image description here

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:

enter image description here

Willy David Jr
  • 8,604
  • 6
  • 46
  • 57
17

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.

user7610
  • 25,267
  • 15
  • 124
  • 150
  • 1
    On mac (i'm assuming Linux as well), you can't rely on `nuget sources` if you are using `dotnet restore` (or [VS Mac](https://github.com/NuGet/Home/issues/5555)) because of [this](https://github.com/NuGet/Home/issues/5555#issuecomment-314268677) bug. I had to add the local source to the `~/.nuget/NuGet/NuGet.Config` manually (see this GH [issue](https://github.com/NuGet/Home/issues/5555#issuecomment-525902537)). – gabe Aug 28 '19 at 20:25
4

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.

Donghua Liu
  • 1,776
  • 2
  • 21
  • 30
0
  1. 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)
  1. 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
  2. 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

Duck Ling
  • 1,577
  • 13
  • 20