NuGet.Server is a package provided by the .NET Foundation that creates an ASP.NET application that can host a package feed on any server that runs IIS. Simply said, NuGet.Server makes a folder on the server available through HTTP(S) (specifically OData). It’s easy to set up and is best for simple scenarios.
Create and deploy an ASP.NET Web application with NuGet.Server
- In Visual Studio, select File > New > Project, search for “ASP.NET”, select the ASP.NET Web Application (.NET Framework) template for C#, and set Framework to “.NET Framework 4.6”:
2. Give the application a suitable name other than NuGet.Server, select OK, and in the next dialog select the Empty template, then select OK.
3. Right-click the project, select Manage NuGet Packages.
4. In the Package Manager UI, select the Browse tab, then search and install the latest version of the NuGet.Server package if you’re targeting .NET Framework 4.6. (You can also install it from the Package Manager Console with
Install-Package NuGet.Server.) Accept the license terms if prompted.
5. Installing NuGet.Server converts the empty Web application into a package source. It installs a variety of other packages, creates a
Packages folder in the application, and modifies
web.config to include additional settings (see the comments in that file for details).
Carefully inspect web.config after the NuGet.Server package has completed its modifications to that file. NuGet.Server may not overwrite existing elements but instead create duplicate elements. Those duplicates will cause an “Internal Server Error” when you later try to run the project.
For example, if your web.config contains <compilation debug=”true” targetFramework=”4.5.2" /> before installing NuGet.Server, the package doesn’t overwrite it but inserts a second <compilation debug=”true” targetFramework=”4.6" />. In that case, delete the element with the older framework version.
6. To make packages available in the feed when you publish the application to a server, add each
.nupkg files to the
Packages folder in Visual Studio, then set each one's Build Action to Content and Copy to Output Directoryto Copy always:
7. Run the site locally in Visual Studio (using Debug > Start Without Debugging or Ctrl+F5). The home page provides the package feed URLs as shown below. If you see errors, carefully inspect your
web.config for duplicate elements are noted earlier with step 5.
8. Click on here in the area outlined above to see the OData feed of packages.
9. The first time you run the application, NuGet.Server restructures the
Packages folder to contain a folder for each package. This matches the local storage layout introduced with NuGet 3.3 to improve performance. When adding more packages, continue to follow this structure.
10. Once you’ve tested your local deployment, deploy the application to any other internal or external site as needed.
11. Once deployed to
http://<domain>, the URL that you use for the package source will be
Configuring the Packages folder
NuGet.Server 1.5 and later, you can more specifically configure the package folder using the
appSetting/packagesPath value in
<!-- Set the value here to specify your custom packages folder. -->
<add key="packagesPath" value="C:\MyPackages" />
packagesPath can be an absolute or virtual path. When
packagesPath is omitted or left blank, the packages folder is the default
Adding packages to the feed externally
Once a NuGet.Server site is running, you can add packages using nuget push provided that you set an API key value in
After installing the NuGet.Server package,
web.config contains an empty
<add key="apiKey" value="" />
apiKey is omitted or blank, pushing packages to the feed is disabled.
To enable this capability, set the
apiKey to a value (ideally a strong password) and add a key called
appSettings/requireApiKey with the value of
<!-- Sets whether an API Key is required to push/delete packages -->
<add key="requireApiKey" value="true" />
<!-- Set a shared password (for all users) to push/delete packages -->
<add key="apiKey" value="" />
If your server is already secured or you do not otherwise require an API key (for example, when using a private server on a local team network), you can set
false. All users with access to the server can then push packages.
Removing packages from the feed
With NuGet.Server, the nuget delete command removes a package from the repository provided that you include the API key with the comment.
If you want to change the behavior to delist the package instead (leaving it available for package restore), change the
enableDelisting key in
web.config to true.