Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Hosting Private Package Repositories with NuGet.Server

Tech Jun 20 2

Project Initialization

Open Visual Studio and generate a new ASP.NET Web Application (.NET Framework). Its recommended to target .NET Framework 4.6 or higher to ensure compatibility with modern package features. When prompted, select the Empty project template to keep the server lightweight.

Integrating NuGet.Server

Open the NuGet Package Manager for your project and search for the NuGet.Server package. Alternatively, execute the following command in the Package Manager Console:

Install-Package NuGet.Server

This installation transforms the empty project into a functional OData feed. During the process, a Packages directory is created, and your web.config is automatically updated with necessary configurations.

Caution: Verify the web.config content after installation. The package might append new XML elements rather than replacing existing ones. For instance, if a <compilation> node already exists, a second one might be added for the new framework version. Remove any redundant nodes to prevent runtime configuration errors.

Local Execution and Feed Access

Launch the application locally (Ctrl+F5). The landing page will display the endpoint URL, typically structured as http://localhost:<port>/nuget.

Upon the first run, the server organizes the Packages folder into a structured layout where each package has its own subfolder. This optimizes metadata retrieval for NuGet 3.3+ clients. As you manually add files, ensure you follow this folder-per-package convention.

Enabling Package Uploads

To permit remote package pushing via the NuGet CLI, you must configure an API key in web.config. By default, the key is empty, which prevents external uploads.

Update the <appSettings> section as follows:

<appSettings>
  <!-- Toggle API key requirement for push/delete operations -->
  <add key="requireApiKey" value="true" />

  <!-- Define the authentication token -->
  <add key="apiKey" value="SecureAccessKey_987" />
</appSettings>

Setting requireApiKey to false allows anyone with network access to modify the feed, which might be appropriate for isolated internal networks.

For NuGet 3.0.0 and later, use http://<domain>/nuget as the push endpoint. If you need to support legacy clients that expect the V2 endpoint (/api/v2/package), ensure enableLegacyPushRoute is set to true in your OData configuration file (usually NuGetODataConfig.cs).

Customizing Storage Locations

By default, the server stores files in the ~/Packages directory. You can redirect this to a physical drive or a specific relative path using the packagesPath setting:

<appSettings>
  <!-- Map to a custom storage location -->
  <add key="packagesPath" value="C:\Data\NuGetRepository" />
</appSettings>

Managing Package Lifecycle

When a package is deleted via the CLI, it is removed from the file system. To change this behavior so that packages are hidden from search results but remain available for restoration (delisting), modify the following key:

<appSettings>
  <add key="enableDelisting" value="true" />
</appSettings>

Bundling Packages with Deployment

If you want to include specific .nupkg files during the initial deployment, place them in the Packages folder within the project. In the Solution Explorer, select these files and set their Build Action to Content and Copy to Output Directory to Copy always.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.