DEV Community

Cover image for How to: NuGet local feeds
Karen Payne
Karen Payne

Posted on

How to: NuGet local feeds

Introduction

NuGet packages are the standard way .NET developers share, version, and consume reusable code, whether it’s core libraries, third-party tools, or internal company components. A NuGet package is essentially a zipped bundle that contains compiled assemblies, metadata, and dependency information, which allows Visual Studio and the .NET CLI to automatically restore the correct versions your project needs. This system has been around for years, and it works because it enforces consistency: you no longer copy DLLs by hand; instead, you declare what you depend on and let NuGet manage updates, conflicts, and builds in a predictable and repeatable way.

In this article, learn how to write code to publish to a local source.

Individual accounts on NuGet.org

You must create an individual account to publish and manage packages on NuGet.org.

Local feed/source

A NuGet local feed is simply a folder on your machine or network that NuGet treats as a package source, allowing you to create, store, and consume NuGet packages without publishing them to a remote repository like nuget.org.

Local feeds are fast, offline-friendly, and ideal for in-house or experimental packages; however, they lack the governance, versioning discipline, and auditability that you get from a proper package server.

When to create local packages

  • A developer uses the same code over and over again.
  • The code is proprietary to a developer or an organization.
  • Easy to maintain and allows multiple versions to be available.

Starter example 1

A developer or team of developers needs to create a type handler for Dapper to understand DateOnly and TimeOnly structs. This would be a good example which in this case could be local or public as shown here.

public class SqlDateOnlyTypeHandler : SqlMapper.TypeHandler<DateOnly>
{
    public override void SetValue(IDbDataParameter parameter, DateOnly date) 
        => parameter.Value = date.ToDateTime(new TimeOnly(0, 0));
    public override DateOnly Parse(object value) => DateOnly.FromDateTime((DateTime)value);
}

public class SqlTimeOnlyTypeHandler : SqlMapper.TypeHandler<TimeOnly>
{
    public override void SetValue(IDbDataParameter parameter, TimeOnly time)
    {
        parameter.Value = time.ToString();
    }

    public override TimeOnly Parse(object value) => TimeOnly.FromTimeSpan((TimeSpan)value);
}
Enter fullscreen mode Exit fullscreen mode

Starter example 2

A developer or a team develops a proprietary API that is solely used internally. These packages need to be protected as a seasoned developer, or a hacker can easily get to the package source code. A package file is just as easy to hack as a .DLL file.

Publishing to Local feed/source tool

The purpose of a tool is to copy a package file to a local feed folder for personal use or for a team of developers.

Source code

Screen shot

The tool

Using the tool

Select a package, then select a version of the package. Click the Publish button, which presents a confirmation dialog to continue. If a package exists, it will be overwritten when clicking yes in the confirmation dialog.

Configuration

To configure the tool: open appsettings.json

PackageLocation points to the folder where your local NuGet packages are stored for Microsoft Visual Studio.

Visual Studio options dialog for NuGet package sources
Visual Studio options dialog for NuGet package sources

ClassProjects section: In this section, add one or more paths to project folders that contain one or more .nupkg files.

  • A path points to a project folder not the path to nupkg files.
  • Paths can be in one or more Visual Solutions.

Example appsettings.json file with five paths; each path in ClassProjects points to a project under different Visual Studio solutions.

{
  "PackageLocation": "C:\\NuGetLocal",
  "ProjectItems": [
    {
      "Path": "C:\\DotnetLand\\VS2022\\ProjectTemplates2025\\SpectreConsoleLibrary"
    },
    {
      "Path": "C:\\DotnetLand\\VS2022\\BogusTrainingSolution\\BogusLibrary"
    },
    {
      "Path": "C:\\DotnetLand\\VS2022\\SerilogSolution\\SeriLogThemesLibrary"
    },
    {
      "Path": "C:\\DotnetLand\\VS2022\\ConsoleHelpersSolution\\ConsoleConfigurationLibrary"
    },
    {
      "Path": "c:\\DotnetLand\\VS2019\\dapper-libraries\\Dapper.Handlers"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Important

💡 The method DirectoryHelper.ProjectItems traverses folders specified from ClassProjects in appsettings.json. Only paths that exist and contain at least one .nupkg will be displayed in the tool.

Summary

Instructions and why a developer or team of developers may want to use local NuGet packages along with a tool to copy packages to a local feed folder in this article to assist with working with local NuGet packages.

Top comments (0)