Hosting a Simple “Read-Only” NuGet Package Feed on the Web

nuget, asp.net, code 0 comments suggest edit

As you may know, NuGet supports aggregating packages from multiple package sources. You can simply point NuGet at a folder containing packages or at a NuGet OData service.

A while back I wrote up a guide to hosting your own NuGet feed. Well, we’ve made it way easier to set one up now! And, surprise surprise, it involves NuGet. Smile I’ll provide step by step instructions here. But first, make sure you’re running NuGet 1.2!

Step 1: Create a new Empty Web Application in Visual Studio

Go to the File | New | Project menu option (or just hit CTRL + SHIFT + N) which will bring up the new project dialog and select “ASP.NET Empty Web Application” as in the following screenshot (click to enlarge).

new-project-dialog

This results in a very empty project template.

empty-web-project

Step 2: Install the NuGet.Server Package

Now right click on the References node and select Add Library Package Reference to launch the NuGet dialog (alternatively, you can use the Package Manager Console instead and type Install-Package NuGet.Server).

Click the Online tab and then type NuGet.Server in the top right search box. Click Install on the NuGet.Server package as shown in the following image (click to enlarge).

nuget-dialog

Step 3: Add Packages to the Packages folder

That’s it! The NuGet.Server package just converted your empty website into a site that’s ready to serve up the OData package feed. Just add packages into the Packages folder and they’ll show up.

In the following screenshot, you can see that I’ve added a few packages to the Packages folder.

packages-folder

Step 4: Deploy and run your brand new Package Feed!

I can hit CTRL + F5 to run the site and it’ll provide some instructions on what to do next.

package-site

Clicking on “here” shows the OData over ATOM feed of packages.

package-feed

Now all I need to do is deploy this website as I would any other site and then I can click the Settings button and add this feed to my set of package sources as in the following screenshot (click to enlarge).

Options

Note that the URL you need to put in is http://yourdomain/nuget/ depending on how you deploy the site.

Yes, it’s that easy! Note that this feed is “read-only” in the sense that it doesn’t support publishing to it via the NuGet.exe command line tool. Instead, you need to add packages to the Packages folder and they are automatically syndicated.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

46 responses

  1. Avatar for Troy
    Troy March 31st, 2011

    I can get it running fine on my machine...but when i publish to a fresh Win 2008/IIS 7.5 box the feed url returns a 404 Not Found. I've got .net 4.0/mvc 3.0 installed on the machine. Is there a config step i likely missed that NuGet needs?

  2. Avatar for haacked
    haacked March 31st, 2011

    You need to map the application/zip mime type to *.nupkg in IIS. We're going to try and change our package do that for you. :)

  3. Avatar for Betty
    Betty March 31st, 2011

    I played with this a couple days ago, I was disappointed to see it couldn't be extended easily to host multiple feeds.

  4. Avatar for Flash
    Flash March 31st, 2011

    I had the same problem as Troy when I deployed to IIS 7.5 (i.e. error code 404 on package feed). Once I added the magic runAllManagedModulesForAllRequests="true" attribute to the system.webServer/modules element in the web.config it worked.

  5. Avatar for oleksii
    oleksii March 31st, 2011

    This is really cool and useful for me. Thanks!

  6. Avatar for Troy
    Troy April 1st, 2011

    I'm a NuGet noob so be patient with me :)
    The fix that @Flash suggested worked great. Now my NuGet feed is working fine, and I can view it via a web browser. The issue is in Visual Studio. I get the following:
    get-package -remote
    Get-Package : There was an error while processing the request. Please verify that 'http://myserver:8080/nuget/Packages' is a valid feed.
    At line:1 char:12
    + get-package <<<< -remote
    + CategoryInfo : NotSpecified: (:) [Get-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.GetPackageCommand

    Am I still missing something?

  7. Avatar for Daniel Liuzzi
    Daniel Liuzzi April 1st, 2011

    Is it possible to have the feed require authentication? This would come incredibly handy for teams where developers are scattered over the world, and need a centralized repository for their private packages. Thanks!

  8. Avatar for Troy
    Troy April 1st, 2011

    Solved!
    I was using 'http://myserver:8080/nuget/packages' as the feed url. Turns out that NuGet automagically appends '/Packages' to the feed url for you. Once I changed it to 'http://myserver:8080/nuget' everything was right in the world again.

  9. Avatar for haacked
    haacked April 2nd, 2011

    @Betty Just have multiple sites. It's pretty easy.
    @Daniel I don't think we support authenticated feeds. One way you could do it is to use Basic authentication with HTTPS and supply the authentication information in the URL. Hacky and ugly, I know. Just haven't had a large number of requests for it.
    There is a bug in our backlog on this: http://nuget.codeplex.com/workitem/366

  10. Avatar for Betty
    Betty April 2nd, 2011

    @haacked, multiple sites works but it really wouldn't have been hard for the author to have fixed that minor issue. Single site would allow making migrating packages from the beta/ci feed to the production one a lot easier (cleaner) too.

  11. Avatar for Tugberk (tourismgeek)
    Tugberk (tourismgeek) April 3rd, 2011

    sir,
    we have been thinking doing something like that as company for only our private libraries but how can we protect the feed? with api key of authorization headers?

  12. Avatar for Tugberk (tourismgeek)
    Tugberk (tourismgeek) April 3rd, 2011

    there is a typo on my previous comment. last sentence should have been like below;

    how can we protect the feed? with api key or authorization headers?

  13. Avatar for Tugberk (tourismgeek)
    Tugberk (tourismgeek) April 3rd, 2011

    ok. I really sucked here. you already posted an answer to @Daniel about the same issue I am curious about. sorry for the verbosity :S

  14. Avatar for Michael Ceranski
    Michael Ceranski April 4th, 2011

    I took the code a step further by adding a package upload form and a formatted package list using XSLT. I wrote a post about it and put my code on bitbucket. Contributors are welcome.
    Thanks Phil!

  15. Avatar for Rick Schott
    Rick Schott April 4th, 2011

    NuGet is really coming along, great post.

  16. Avatar for haacked
    haacked April 5th, 2011

    @Michael, would you mind submitting a pull request to nuget.codeplex.com with that change? :)

  17. Avatar for Jacco
    Jacco April 6th, 2011

    I realy like this solution, but I don't get it. Keep getting the 404 error. I made sure having the <modules runAllManagedModulesForAllRequests="true"> entry in web.config.
    Published the site to IIS 7 and added the mimetype as suggested by haacked.
    Anyone any other suggestion? please....

  18. Avatar for Damian Powell
    Damian Powell April 10th, 2011

    It seems that WebActivator now depends upon Microsoft.Web.Infrastructure but it isn't included as a reference. Is that intentional?

  19. Avatar for Damian Powell
    Damian Powell April 10th, 2011

    This is very cool, BTW. I should have opened with "Thanks" rather than "Why does this depend on Microsoft.Web.Infrastructure". Where were my manners?
    I was just wondering though, does the team have any plans to modify NuGet.Server to allow uploading of new packages in the future?

  20. Avatar for David Nelson
    David Nelson April 11th, 2011

    I am excited about using NuGet to manage our company's internal collection of libraries; previously we have stored everything on our intranet, and although it is functional, there are numerous problems which I hope NuGet will solve.
    However, currently I am having trouble getting my NuGet server running on my development web server. It complains that it "Could not load file or assembly 'Microsoft.Web.Infrastructure..." It seems that NuGet.Server has an external dependency that I don't have installed; but I can't find anything that mentions such a dependency.

  21. Avatar for AntiGameZ
    AntiGameZ April 13th, 2011

    Is there any easy way to get packages from the offical source so that I can put them in my own?

  22. Avatar for haacked
    haacked April 16th, 2011

    Use Package Explorer. http://nuget.codeplex.com/releases

  23. Avatar for haacked
    haacked April 16th, 2011

    @David it requires the ASP.NET Web Pages runtime. You can install ASP.NET MVC 3 to get it.

  24. Avatar for haacked
    haacked April 16th, 2011

    Actually, just right click on the Project Properties in VS and select "Add Deployable Assemblies" and select ASP.NET MVC" before deploying. It'll add the right dependencies.

  25. Avatar for mcdon
    mcdon April 20th, 2011

    Can NuGet.Server be hosted on XP Pro and Windows Server 2003? My attempts at hosting have been unsuccessful.

  26. Avatar for haacked
    haacked April 20th, 2011

    I think it requires ASP.NET 4. Should run on XP/2003.

  27. Avatar for Dave Sussman
    Dave Sussman April 20th, 2011

    Phil - just a warning; adding the deployable dependencies causes a version mismatch. I just isntalled the Web Pages on my server instead.

  28. Avatar for Tim Cartwright
    Tim Cartwright April 22nd, 2011

    This worked great, however I am running into an issue with dependencies. Using the package explorer I added a dependency to jquery. (Actually it happens with any dependency)
    I see the package fine in visual studio, however when I go to install I get "unable to resolve dependency".
    If I remove the dependencies the package installs fine.

  29. Avatar for Matt
    Matt April 26th, 2011
    @David it requires the ASP.NET Web Pages runtime. You can install ASP.NET MVC 3 to get it.


    Shouldn't this come down as a dependency then? Seems wonderfully ironic that a dependency manager should fail to manage it's own dependencies...

  30. Avatar for haacked
    haacked April 27th, 2011

    @Matt. Yeah, we're looking into it. :)

  31. Avatar for Sergi Gisbert
    Sergi Gisbert May 3rd, 2011

    Hi Phil,
    We are trying to put all our private libraries into a private Nuget repository, but we have a problem: some of our private libraries depend as well on 3rd party libraries from the official repository, like the EntLib.
    I don't really want to manually download those packages from the official repository to my local one, because of redundancy and the updates nigthmare... So, is there a way to specify the repository source in the <dependency> tag at the .nuspec file? or somewhere? Should Nuget search for the dependencies in all the sources in the "Online" tab?
    Thanks,
    Sergi

  32. Avatar for Shaun McCarthy
    Shaun McCarthy May 4th, 2011

    When you deploy this to a live server that binds multiple websites to the same IP Address, make sure to set &lt;serviceHostingEnvironment multipleSiteBindingsEnabled=&quot;true&quot; /&gt; in your web.config file; otherwise, you will end up getting error messages along the lines of "This collection already contains an address with scheme http".
    I've listed a few other gotchas on my blog

  33. Avatar for haacked
    haacked May 4th, 2011

    @Shaun add your private repository to the package sources and move it to the top so it's first. Then use the "All" node when installing packages. It'll look in your private repository first, then in the others if the package isn't in your private.

  34. Avatar for Mike
    Mike May 10th, 2011

    You are missing a step to add the dependency on Microsoft.Web.Infrastructure, and that is not a NuGet package :(

  35. Avatar for Kevin Wilson
    Kevin Wilson July 14th, 2011


    Tried following the instructions but am getting the error
    The exception message is 'Could not load file or assembly 'NuGet.Core, Version=1.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
    when trying tp browse to view the feeds (http://localhost:49850/nuget/Packages). Same error on both my local machine and server.
    NuGet.Core is in the bin but the version shown in the packages.config is 1.4.20615.9012. I can't see any specific references to 1.4.0.0 anywhere.
    Any ideas what to do?
    Thanks.

  36. Avatar for Kevin Wilson
    Kevin Wilson July 14th, 2011

    Also added this to config as suggested online but just changes the error to tell me that it can't reference v1.4.20615.9012.
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="NuGet.Core" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-1.4.0.0" newVersion="1.4.20615.9012"/>
    </dependentAssembly>
    </assemblyBinding>
    </runtime>

  37. Avatar for Frank C.
    Frank C. August 22nd, 2011

    I tried this and it seems to work. However, the private repository does not list any packages when using the nuget.exe tool with the List command. Any ideas?

  38. Avatar for Doug
    Doug April 12th, 2012

    Just got the latest NuGet goodies. 1.7.1 server is not working for me. I can see the packages in the web browser. I can browse the packages in the manager. But any attempt to install a package result in a 404 error.

  39. Avatar for Robbie
    Robbie April 20th, 2012

    I have the same problem as Doug except that if I add a trailing backslash to teh request VS makes, then it works.
    The question is;
    How do I get VS to add the trailing backslash or how do I get IIS to handle the missing backslash?

  40. Avatar for Galal
    Galal July 23rd, 2012

    Well first of all good job,
    secondly i wanna vote for making nuget supports authentications,
    what can i do for now is to authenticate requests that come from specific IP. but hope that i can do more.
    Thanks :)

  41. Avatar for Dan Miser
    Dan Miser December 1st, 2013

    I added a quick addition to get this to work inside an Azure WebSite Virtual Application:

    Nuget.Server in an Azure WebSite Application

  42. Avatar for Mike Devenney
    Mike Devenney January 8th, 2014

    Thanks Phil, this is great! I've hit an issue where clicking the "here" link shows the XML of the packages and not the nicely formatted feed page that your's does. What did I miss?

  43. Avatar for haacked
    haacked January 9th, 2014

    That formatting is done by the browser. The actual URL really is just XML content.

  44. Avatar for badoka
    badoka June 16th, 2014

    Hi,

    I am hosting own NuGet feed with latest version from Nuget.Server.

    That is IIS Web application developed by
    http://docs.nuget.org/docs/...

    Application is working correctly, if we are using latest version from
    Nuget package e.g. XXXXXX.Common.DataTypes V.2.0.0, but if we are using
    previous version e.g. XXXXXX.Common.DataTypes V.1.0.0 we have from
    Visual Studio the following message The version
    1.0.0 from packet XXXXXX.Common.DataTypes is not found.

    All package file are published correctly and Nuget as a file server is working correctly with the same folder.

    The problem seems to be something with IIS............

    Thanks

  45. Avatar for leandro koiti
    leandro koiti February 25th, 2015

    amazing post, that saved me a lot of precious time, thank you so much!!

  46. Avatar for Kevin Swanson
    Kevin Swanson September 12th, 2015

    I had some of the same issues that a few others listed, and nothing I found online helped. I did finally resolve it, and in my case it was related to new versions of either NuGet.Server or some dependency that requires .Net 4.5. It took me several hours to finally figure that out.

    In your first screen print on step 1, if you change the drop-down to .Net Framework 4.5, everything works great.

    In Visual Studio 2013, you also can't find the "ASP.Net Empty Web Application" template under "web". You have to drill down own more level to Web/Visual Studio 2012.