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
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.
- Create an empty ASP.NET MVC(or WebForms) project.
- Download the NuGet.Server package from the official NuGet feed. This will create a simple oData feed.
- Deploy the application to a webserver of your choice.
- 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
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:
- Download the latest source from GitHub.
- Navigate to the Website subdirectory and open the web.config. Inside the web.config change the following options:
- Modify the configuration/connectionStrings/NuGetGallery key so it points to your locally hosted SQL Server.
- Change the appSettings/GalleryOwnerEmail to the email address of the person who is going to administer the site.
- Change the appSettings/Configuration:SiteRoot to reflect the domain name you are going to use for the site.
- Run the Build-Solution.ps1 script using Powershell in the root directory. This will compile the website and assemble the binaries.
- Open up your IIS Manager
- Create a new application pool. The pool should use the 4.0 framework and use an integrated pipeline.
- 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.
- Open up SQL Server Management Studio
- 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.
- 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.