Friday, February 8, 2013

Hosting your own NuGet feeds

There are multiple ways to host your own NuGet feeds:

  • Using a fileshare
  • Using MyGet
  • Using the NuGet server package
  • Using the NuGet Gallery  code
Hosting your NuGet feeds using a fileshare

This is probably the easiest solution. Just create fileshare on a server somewhere and put all your packages on this share. This approach has one big disadvantage, it becomes rather slow when the number of packages grows.

Hosting your NuGet feeds on MyGet

image

MyGet, also known as ‘NuGet as a Service’ allows you to create and host your own NuGet feed. It allows you to include packages from the official NuGet feed or upload your own NuGet packages. It offers lots of nice features and best of all if you don’t need private feeds, it’s free!

Hosting your NuGet feeds using the NuGet server package

This option needs a little bit more work.

  1. Create an empty ASP.NET MVC(or WebForms) project.
  2. Download the NuGet.Server package from the official NuGet feed. This will create a simple oData feed.
  3. Deploy the application to a webserver of your choice.
  4. Add or remove packages by putting them in the Packages folder that is created for you.

Big advantage of this approach is that it introduces some caching improving the performance of the NuGet feeds.

Hosting your NuGet feeds using the NuGet Gallery

image

The last option but also the most complex one is to use the NuGet gallery, the same code that the NuGet team is using to host NuGet.org. Unfortunately you’ll have some work to get everything up and running:

  1. Download the latest source from GitHub.
  2. Navigate to the Website subdirectory and open the web.config. Inside the web.config change the following options:
    1. Modify the configuration/connectionStrings/NuGetGallery key so it points to your locally hosted SQL Server.
    2. Change the appSettings/GalleryOwnerEmail to the email address of the person who is going to administer the site.
    3. Change the appSettings/Configuration:SiteRoot to reflect the domain name you are going to use for the site.
  3. Run the Build-Solution.ps1 script using Powershell in the root directory. This will compile the website and assemble the binaries.
  4. Open up your IIS Manager
    1. Create a new application pool. The pool should use the 4.0 framework and use an integrated pipeline.
    2. Create a new website. Set the site’s physical path to point at the Website directory. Also make sure the site uses the application pool that you created in the previous step. Do not start the website yet.
  5. Open up SQL Server Management Studio
    1. Grant db_creator to the identity of the application pool you created earlier. The account needs db_creator because the first time you run the application, the Entity Framework context initializer will run. If no database exists yet then it will create the database for you. After the database is created, you can trim back the permissions to db_datareader and db_datawriter.
  6. Navigate to the NuGet gallery website. It may take a second or two for the page to appear because the database gets created during the first run.

1 comment:

Frank Moss said...

Clearly everything is made easy by following your steps. It is very much appreciated. Many thanks.