Create and Publish NuGet Package in Windows Azure

Recently I came up with a situation where I need to re-use few libraries in many projects. One way to do this is to refer the latest library in every projects of your existing or any other solutions which I am not comfortable with at all. The other way to avoid this traditional approach of directly adding references of your library to the project is to use NuGet Packager which I like the most. Well we might all know that having the library located in a common repository of NuGet Server makes more sense in order to re-use it multiple places. Also you can keep multiple versions of the library and use it as per client requirement. If client requires the latest package or a specific old versioned package, its relatively a lot easier to refer the library through NuGet Package Manager or Console.

Well keeping all these in mind, my situation was that I need to deploy this library in a NuGet Server that can be accessible by resources globally. I also know I do not have a global server that can be used. Hence the only option I have is to deploy the package in Windows Azure as I have a subscription on it and see how it works.

Create an Empty Web Application

First I started creating an empty Web Project from VS2013. While creating the website, it will also provide me an option to select the Web Host where the site would be hosted. I had selected that option so that my Web Host repository gets created.

Once an empty Website is created use the package manager console to add NuGet.Server library to the web project in order to provide the facility to create your web server.

PM> Install-Package NuGet.Server

This will add few libraries and folders in your empty web project as shown below.



Open the web.config file and validate that you have requireApiKey value set to True and have added an apiKey so that no unauthorized user can have permission to create the package and publish it to repository.



Run the solution pressing F5 and you would see the following web page in your explorer.



In order to push any package to the server you need to run the following command from Command Prompt.

nuget push {package file} –s http://localhost:61342/ {apikey}

Well our agenda is to push the package to Azure web app instead of localhost. Hence our next step is to configure our Web Publishing activity to create the NuGet Web Server in Azure.


Update the settings for publishing to your Windows Azure repository

While creating the web project we have selected the Web Host location where the files need to be deployed. In this step you need to update the parameters for publishing and creating the NuGet Web Server in Azure. Select the settings option of Web Publish Activity to update the parameters.




Remember to select Microsoft Azure Websites from Publish Target section.



Once you have selected the Target location, you need to validate the connection to the Target location for the Web Publishing method.



Next step is to publish it. Make sure that you are publishing the website in Release Mode and also no databases are required.



Once the web site is published in your Azure account, you can review the website using the Url created after the publishing activity is complete.




You can even verify from your Azure account that the web server has been created through



Well we are all set to go for publishing our packages to the web server.


Publish your package to the web server

Select the Project you want to publish as a NuGet package to your NuGet Server.

Use the package manager console to add CreateNewNuGetPackageFromProjectAfterEachBuild library to the project in order to create the NuGet package *.nupkg file on every build.

PM> Install-Package CreateNewNuGetPackageFromProjectAfterEachBuild

The following files will get generated in your project.



Now right click on the Project and Build it. This will create your NuGet Package.



Once your package is generated, copy the package and place it in a folder where NuGet.exe resides. NuGet.exe will help to publish the package to the new NuGet Server that has been created in your Azure account.

You can download NuGet.exe from the following location

Now open your Command Prompt and run the following command nuget push {package file} –s http://{Azure NuGet Web Server address}/ {apikey}



Your package is now deployed in NuGet Web Server.


Apply your package to a project pointing to NuGet Web Server hosted in Azure

Next step is to consume your NuGet Package from your newly created NuGet Server location.

Add you package source in NuGet Package Manager interface.



Now you can install the package using Manage NuGet Packages option while right-clicking on the project where you want the package to get installed.



That’s it you are good to go with NuGet package….

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.