Michael Ceranski is a .NET developer from Buffalo NY. He has been writing code for over 10 years starting with Borland Delphi and later migrating to the .NET stack. Michael enjoys blogging about .NET, MVC and jQuery. When Michael is not consulting he spends his time working on WeBlog, a next generation blogging platform written in ASP.NET MVC 2. Michael is a DZone MVB and is not an employee of DZone and has posted 34 posts at DZone. You can read more from them at their website. View Full User Profile

How to Set Up a Local NuGet Gallery

02.06.2012
| 9388 views |
  • submit to reddit

First of all you may be wondering, why do I want my own local Nuget Gallery? Well, here are two reasons:

  • Having your own NuGet server is perfect for when you need share modules with other people on your team but you do not necessarily want to make them available for public consumption.
  • If you are a consultant then having your own personal NuGet Gallery may be a handy way to keep your libraries and utilities accessible to you when you are on the road. This is an great way to utilize your home broadband connection.

Last year I wrote an article about how to Build a NuGet Server with gold plating. At the time, there were two methods for hosting your own NuGet feed. The first option was to install the Orchard-based NuGet Gallery. I personally stayed away from this option because setting up an entire CMS just to host a few small NuGet packages seemed like overkill to me. The second option was to create an empty ASP.NET MVC site and install a few NuGet packages from Phil Haack that turned your empty website into a NuGet server. I call the second option the recursive NuGet server because you install NuGet packages which in turn help you to create a NuGet server. Anyway, if you compare the features of the Orchard Nuget Gallery to the recursive NuGet server, you will instantly notice that the Orchard version had a lot more functionality. Unfortunately, at the time I still could not justify setting up an entire CMS just to get a few small features.

Eventually someone on the NuGet team realized that having the gallery so tightly coupled with Orchard was probably not a good idea. So sometime late last year, the NuGet gallery was removed from Orchard which made the setup process a lot less complex. Unfortunately the documentation page for Setting Up a Local NuGet Gallery has not been updated yet and still reflects the steps for creating the Orchard-based gallery. Since I recently setup a NuGet server at the office I decided to document the new steps in order to save you some trouble.

  1. Download the latest source from GitHub. I just grabbed the zip file since I do not have a Git client on my machine.
  2. Extract the zip file and navigate to the Website subdirectory. Locate the web.config file and open it up in your favorite editor. Inside the web.config you will want to 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. Please pay careful attention to the Identity of the pool because you will need to grant this account permissions to your SQL Server.
    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 applicaton, 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. This tends to make your DBA happy.
  6. Start your website and launch the browser of your choice. In the browser, navigate to the NuGet server. It may take a second or two for the page to appear because the database needs to get created during the first run.

If you followed the steps properly then you should see the following page:

image

References
Published at DZone with permission of Michael Ceranski, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)