Hosting Private Package Repositories with NuGet.Server
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.configcontent 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.