This Code Bytes

Programming Tidbits

30. March 2013 16:45
by Brad Falk
0 Comments

Consuming a NuGet package from a private NuGet feed

30. March 2013 16:45 by Brad Falk | 0 Comments

In the last post I showed how you can create a custom NuGet package using the NuGet Package Explorer. This post will show how to create a simple private NuGet feed and consume the packages in that feed in Visual Studio.
Here are the steps involved:

  1. Create the private feed – in our example this will simply be a folder out on a network share.
  2. Notify the Package Manager in Visual Studio know about the private feed.
  3. Install the package in your project via the “Manage NuGet Packages” interface.
Create the Private Feed

There are plenty of references on the internet for creating your own NuGet feeds, including this one from the NuGet documentation. If you read that you’ll see that a private feed can be as simple as a local folder or you can host a remote (or internal) feed with a web application using NuGet Server. What I’m going to show here is sort of in between the two, using a folder on a network share so that it can be shared amongst the team, and keep it simple at the same time.

So, you can see from the screenshot below that I created a NuGet Packages folder, under a Development share on MyServer, and I copied over the NuGet package that I created in the last post:
Private_Feed

Guess what? We’re done! That’s all it takes to create a “feed” that we can point Visual Studio at so that it’s aware of our packages.

Configure Visual Studio

Now we need to let the Package Manager in Visual Studio know about this feed. In Visual Studio go to Tools –> Options –> expand the Package Manager node in the left pane and select Package Sources.
From here, click the Plus button at the upper right, give your feed a Name and a Source path – as you see I gave it the path to the network folder from the previous step:
Package_Manager

Click Ok and that’s all there is to it. Now Visual Studio is aware of your feed and you’ll be able to install packages from that location.

Install the Package in a Visual Studio project

Okay, now let’s finally get down to reaping the benefits of our work. To install the package just right click on the references folder in the project that you wish to use the package, and select the Manage NuGet Packages option:

ManagePackageMenu

This will open the Manage NuGet Packages dialog. Notice that under the ‘Online’ section in the left pane, you should see the custom feed we installed in the previous step and the middle pane should contain our custom Kendo package:

ManagePackagesDialog

Just click the Install button next to the package name and all of the files should be pulled into your project, and we’ll have the result we were looking for in the last post:

solution_explorer

Updating the package

Updating the package to a new version is also a breeze using NuGet. Coincidentally, Telerik released a new version of Kendo UI since my last post. So, I created a new package, with the latest Kendo version, using the same steps as my last post and copied that new package into my private feed location:

NewPackage
Now, when I go into the Manage Nuget Packages dialog, and switch over to the Updates section, I should see my new package show up:

UpdatePackage

What’s happened here is that the NuGet Package Manager has detected that one of the packages that I have installed in this project has a newer version in our feed. So, now we just have to click the Update button and NuGet will pull down the new version of the package and update the files in our project with the new version. Doesn’t get any better.

Summing Up

Hopefully I’ve been able to show some of the coolness of NuGet and demonstrate how easy it is to create your own packages, private feeds and bring all of that together to manage the dependencies you have on third party tools that don’t already have packages out on the official NuGet package source.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading