How to Set Up a Local NuGet Gallery
How to Set Up a Local NuGet Gallery
Join the DZone community and get the full member experience.Join For Free
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.
- Download the latest source from GitHub. I just grabbed the zip file since I do not have a Git client on my machine.
- 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:
- 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. Please pay careful attention to the Identity of the pool because you will need to grant this account permissions to your SQL Server.
- 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 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.
- 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:
Published at DZone with permission of Michael Ceranski , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.