Sunday, February 10, 2013

Hosting Nuget Feeds

In this post we are going to see how we can create nuget feeds for intra-organization needs. Since these packages are not intended to be shared outside the organization, we don't need to host them on nuget.org. Nuget feeds can be directly created from file system folder or they can be hosted on a web server.

Package Feeds from Network Share
We can simply setup a Nuget repository on a server. We can simply create a folder which could be shared across the network. This is called Poor Man Nuget Repository. Let's use MyTestPackage.1.0.0.nupkg created earlier and copy that into the folder used as the repository. The configuration for the repository can be done in Tools -> Options. The developers need to provide this configuration in their Visual Studio 2012.


After configuring the repository, they can use it to source their nuget packages. You should be able to see the repository in the Nuget Package Manager. Please also notice the metadata for the package.


Hosting Nuget Packages on a Web Server
We can also host nuget packages on a web server. We can easily create a web application and use it to host nuget packages. This technique is specified here [http://docs.nuget.org/docs/creating-packages/hosting-your-own-nuget-feeds]. Let's create an empty ASP.net web application in Visual Studio 2012 as follows:


The most amazing part is that Microsoft has provided a nuget package to help organizations hosting their nuget repositories for intra-organization consumption. The package is available on nuget.org. We can add the package to our web application as follows:


Look at the package dependencies for this package.


In order to run the application I needed to update <system.web> section as follows for hosting in the selected framework:


Visual Studio 2012 Ultimate can host it directly in IIS Express. Let's run the application and see the following page:


The application will source the packages from "Packages" folder in the solution. This is configurable. We can update the following app setting in web.config.


This is the same folder we were using to host the packages directly from file system. Let's run the application now. This should update the view as follows:


We can add this as a package source for client applications.


Packages can be added from the source now as follows:


We can also support clients to publish nuget packages and contribute to the feed. The web server host is secured through the following settings:


For our testing, let's just disable it. Now let's create another package and use Package Explorer to publish it to the nuget feed as follows:


Now you can see that the new package is available to the feed now:


Download:

No comments: