DEV Community

Cover image for How to install NuGet Packages locally
Camilo Martinez
Camilo Martinez

Posted on • Edited on

12 1

How to install NuGet Packages locally

If you are a NuGet package creator and want to test it before publish them, just need to register a new source in NuGet.Config file.

OS Path
Win %appdata%\NuGet\NuGet.Config
Mac ~/.nuget/NuGet/NuGet.Config

Open your file, and inside packageSources add a new local key following this structure <add key="local" value="path" />. This path can be a relative or absolute from NuGet.config folder.



<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="local" value="/Users/username/NuGet/Packages" />
  </packageSources>
</configuration>


Enter fullscreen mode Exit fullscreen mode

Now you can install a package locally with dotnet add package and source option to local.

dotnet add package <PACKAGE_NAME> -s local

NuGet will search the nupkg file to be restored from your local folder.


When you want to switch to restore de Package from nuget.org. That may show a message saying it is unable to find the new version. You'll need to clear your local packages cache before restoring.

dotnet nuget locals --clear all

Afterward, you can restore packages without a problem:

dotnet restore or dotnet build


That’s All Folks!
Happy Coding 🖖

beer

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (2)

Collapse
 
platinumlucario profile image
Platinum Lucario

I tried following everything you said in there, it doesn't work...

C:\Users\Silve\source\repos\VGMusicStudio\VG Music Studio - GTK4>dotnet add package C:\Users\Silve\source\repos\VGMusicStudio\CreateNugets\bin\Release\VGMusicStudio.Dependencies.Adwaita.Native.win-x64.1.6.3.nupkg -s local

Build succeeded in 1.2s
info : X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
info : X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
info : Adding PackageReference for package 'C:\Users\Silve\source\repos\VGMusicStudio\CreateNugets\bin\Release\VGMusicStudio.Dependencies.Adwaita.Native.win-x64.1.6.3.nupkg' into project 'C:\Users\Silve\source\repos\VGMusicStudio\VG Music Studio - GTK4\VG Music Studio - GTK4.csproj'.
error: There are no versions available for the package 'C:\Users\Silve\source\repos\VGMusicStudio\CreateNugets\bin\Release\VGMusicStudio.Dependencies.Adwaita.Native.win-x64.1.6.3.nupkg'.
Enter fullscreen mode Exit fullscreen mode

And when I try to put in --version followed by the version number, this happens:

C:\Users\Silve\source\repos\VGMusicStudio\VG Music Studio - GTK4>dotnet add package C:\Users\Silve\source\repos\VGMusicStudio\CreateNugets\bin\Release\VGMusicStudio.Dependencies.Adwaita.Native.win-x64.1.6.3.nupkg -s local --version 1.6.3

Build succeeded in 1.0s
info : X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
info : X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
info : Adding PackageReference for package 'C:\Users\Silve\source\repos\VGMusicStudio\CreateNugets\bin\Release\VGMusicStudio.Dependencies.Adwaita.Native.win-x64.1.6.3.nupkg' into project 'C:\Users\Silve\source\repos\VGMusicStudio\VG Music Studio - GTK4\VG Music Studio - GTK4.csproj'.
info : Restoring packages for C:\Users\Silve\source\repos\VGMusicStudio\VG Music Studio - GTK4\VG Music Studio - GTK4.csproj...
error: NU1101: Unable to find package C:\Users\Silve\source\repos\VGMusicStudio\CreateNugets\bin\Release\VGMusicStudio.Dependencies.Adwaita.Native.win-x64.1.6.3.nupkg. No packages exist with this id in source(s): C:\Users\Silve\source\repos\VGMusicStudio\VG Music Studio - GTK4\local
error: Package 'C:\Users\Silve\source\repos\VGMusicStudio\CreateNugets\bin\Release\VGMusicStudio.Dependencies.Adwaita.Native.win-x64.1.6.3.nupkg' is incompatible with 'all' frameworks in project 'C:\Users\Silve\source\repos\VGMusicStudio\VG Music Studio - GTK4\VG Music Studio - GTK4.csproj'.
Enter fullscreen mode Exit fullscreen mode

Either I'm doing it completely wrong, there's something wrong with my csproj, or this guide is completely misleading.

Collapse
 
equiman profile image
Camilo Martinez

Sorry, I'm actually nos working with nuget anymore.
This guide is almos 4 years old, so it's possible that not apply for current versions.

nextjs tutorial video

Youtube Tutorial Series

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series