Tuesday, April 1, 2014

Setting up a local NuGet repository

Building and maintaining a local NuGet gallery helps you facilitate your development process with local packages which you do not want to publish to NuGet.org and make them free. It also helps you maintain and publish stable versions of your product that is accessible to all developers in your company or team. You can also integrate the package publishing from your TFS build to automatically publish stable versions of the package to your local NuGet.

In this post, we'll explore the steps necessary to create and consume your own NuGet gallery.
Prerequisites
Before you can get NuGet up and running you'll need some prerequisite software.
  • Visual Studio 2013
  • PowerShell 2.0
  • NuGet
  • Windows Azure SDK v2.2
  • xUnit for Visual Studio 2013

Setting up local NuGet gallery
Once you have ensured all the prerequisite software is installed. You need to clone the Nuget gallery repository from Git.

After successfully cloning the repository, open the command prompt and run the build command to build the project

The next step is to setup the website in IIS express.
  • Open the windows PowerShell console as Administrator and ensure that your have the execution policy set as UnRestricted.
  • In the PowerShell console, navigate to local NuGet gallery solution folder and run the Ensure-LocalTestMe.ps1 cmdlet from the tools folder

  • After setting up the IIS website, you need to create the database for the local NuGet gallery.
  • Open the Package Manager Console window from Visual Studio 2013
  • Ensure that the Default Project is set to NuGetGallery

  • Set the startup project of the solution to NugetGallery
  • Open the NuGetGallery.sln solution from the root of this repository.
  • Run the Update-Database command in the package manager console as given below.

  • Change the ConfirmEmailAddress settings value in the Web.Config file of the NugetGallery project to false, this disables confirmation of email address on uploading packages to the local gallery

  • Press Ctrl+f5 to run the website in IIS Express.


Configure Package manager settings in Visual Studio
After setting up your private repository, you need to configure Visual Studio to add your repository to the local package sources which works just like the public repository.
  • Open the Package Manager settings

  • Go to the Package Sources section.
  • Click the plus button to add a new source.

  • Specify a name and source of the new gallery

  • Click OK

Creating and uploading a NuGet package
  • To create a package, launch Package Explorer and select File > New menu option
  • Then select the Edit > Edit Package Metadata menu option to edit the package metadata.
  • The final step is to drag in the contents of your package into the Package contents pane. Package Explorer will attempt to infer where the content belongs and prompt you to place it in the correct directory within the package. For example, if you drag an assembly into the Package contents window, it will prompt you to place the assembly in the lib folder.

  • Save your package via the File > Save menu option.

  • After creating a package use the local NuGet gallery website to upload this package.

  • After uploading the package you can use the local gallery site to verify the uploaded package in the packages in the site.

  • Once the package is available in the local NuGet store, you can install this package from Visual Studio



1 comment:

Unknown said...

Thank you very much for this post!
It saved my day ;)