Host Nuget

How to host your own NuGet Packages

There are mainly three different ways you can host your nuget packages privately:

  • Local feed: Packages are placed on a network file share, ideally using nuget init and nuget add to create a hierarchical folder structure (NuGet 3.3+)
  • NuGet.Server: Packages are made available through a local HTTP server
  • NuGet Gallery: Packages are hosted on an Internet server using the NuGet Gallery Project

Microsoft points to other several products that support remote private feeds. For details, see the complete document.

I tried the NuGet Gallery and the VSTS Package Management.

The use of Nuget Gallery is pretty straightforward.

  1. Clone the git repo
  2. Build the application
  3. Publish the website on the web server

The complete documentation can be found in the NuGet Gallery GitHub repository.

This solution is good because it gives a lot more flexibility when it comes to managing your packages. But I concluded that it takes more time to setup, and at the end, you have an entirely new server or website added for you to manage. That is why I decided to go for the Microsoft VSTS solution instead.

2. Microsoft Visual Studio Team Services Package Management

Prerequisites:

  1. Package Management Extension: To create the feed for the packages, you need to add the Package Management Extension from the Visual Studio Marketplace and associate it to the user or group that has permission in the project.

  2. Create a package feed:

A feed is a container for packages. You consume and publish packages through a particular feed. Information on how to Create a feed.

  1. Create a Personal Access Token:

Mac users may need to create a personal access token in VSTS to authenticate when pushing the package to the feed. Follow the instructions here to create the access token.

Steps to publish a package:

  1. Navigate to your feed
  2. Select the option Connect to feed
  3. Download the Nuget + VSTS Credential Provider and unpack the files
  4. Open a command prompt in the folder where the NuGet and the Credential Provider were unpacked
  5. Copy and execute in the prompt the command to add the NuGet source for the package

    nuget.exe sources Add -Name "CalcBasic" -Source "https://alexandressilva.pkgs.visualstudio.com/_packaging/CalcBasic/nuget/v3/index.json"
    
  6. Copy and execute in the prompt the command to push the package to the feed

    nuget.exe push -Source "CalcBasic" -ApiKey VSTS my_package.nupkg
    

1. Don’t forget to replace my_package.nupkg with the path and name of your nuget package

2. The commands are for windows, if you are in a Mac you have to loose the .exe extension and run the command from the path in which NuGet is installed. Usually, /Library/Frameworks/Mono.framework/Versions/Current/Commands/nuget

Consume NuGet packages from a feed in Visual Studio

  1. Navigate to your feed
  2. Connect to the feed
  3. Copy the NuGet package source URL
  4. Inside Visual Studio, add the URL to the Package Sources in the NuGet Package Manager
  5. In the Solution Explorer, right-click in your project and select Manage NuGet Packages
  6. In the right corner, choose your source from the Package Source combo box then search for the package you want to use
  7. Select the package, click Install and you are good to go

References

 
comments powered by Disqus