Cover image for How to install NuGet Packages locally

How to install NuGet Packages locally

equiman profile image Camilo Martinez ・1 min read

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"?>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="local" value="/Users/username/NuGet/Packages" />

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 🖖

Buy me a cofee


Editor guide