Setting Up a Local NuGet Gallery


For a while now I’ve been wanting to hook up our continuous integration process with a local NuGet gallery. The basic idea is for the build process to produce NuGet packages containing components that are used across a number of internal developments. These packaged up components would then be published to a local NuGet gallery where the packages could be located by internal developers and pulled down into projects in Visual Studio that have a dependency on those components. Jetbrains announcement of native support for NuGet within their TeamCity application made this integration even more attractive.

At the time of writing the NuGet documentation on setting up a local gallery server is a little out of date, referring to an older version of the gallery. What follows is a simple set of instructions on getting a local gallery setup.

The NuGetGallery that I wanted to work with is an implementation of the Gallery and OData package feed that runs the http://nuget.org/ site. You’ll need to download the code for the NuGetGallery from GitHub where it’s available as a zip archive or via a read-only GIT repository.

Once you’ve pulled down a copy of the NuGetGallery project make sure that you have the necessary software installed to compile the project. You’ll need:

Both Powershell and the Windows Azure SDK can also be installed via the Microsoft Web Platform Installer.

Building the project

During the process of building the project a new database will be created for the gallery. By default this will be created in the local SQLEXPRESS instance on the build machine. If you need to change the database setup details the simplest approach is to edit the web.config file in the WebSite folder. The default connection string settings are shown below.

  <connectionStrings>
    <add name="NuGetGallery"
            connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=NuGetGallery;Integrated Security=SSPI"
	    providerName="System.Data.SqlClient" />
  </connectionStrings>

Start a command prompt with elevated credentials in the folder that contains the NuGetGallery project. You can either run the windows command prompt as an Administrator or take a look at this post for details of a handy registry hack to add a “Open Command Window Here as Administrator” to the context explorer menu.

Type powershell followed by ENTER to start a windows powershell.

.\Build-Solution.ps1 to invoke the build script

Tip: If the script fails to run and powershell reports that the execution of scripts is disabled on this system the following command should amend the shell execution policy to allow  the script to execute:

C:\PS>set-executionpolicy remotesigned

The Build-Solution script does a whole heap of stuff and is guaranteed to wow your boss if he catches sight of the impressive output that it generates.

Running the Gallery

After the script completes successfully point a web server at the WebSite folder, either a full blown IIS or grab a copy of IIS Express or WebMatrix from the Microsoft Web Platform Installer.

Once you’ve got the site running, you should be able to load the basic NuGet gallery site in a browser.

new nuget gallery

The November 2011 issue of MSDN Magazine contains a great article by Phil Haack on how to manage project libraries with NuGet. Put that information together with the Jetbrains blog post on Native NuGet Support in TeamCity and it’s not going to be difficult to put together a build process that pushes out packages that can be viewed on your local NuGet gallery. Finally, the NuGet docs pages have instructions on how to setup Visual Studio to consume packages from your local gallery feed.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s