NuGet Simple sharing of Visual studio resources

WRITTEN BY Patrick Verbeeten - 12 January 2012

NuGet is an open source initiative that 'Makes it easy to install and update open source libraries in Visual Studio' or so it says on the website. Basically its a Visual Studio plugin that allows you to add packages to individual projects. These packages can contain different things such as assemblies, commonly source files etc. With support for both an online public repository as well as the ability to use local repositories it makes it a good way to save your libraries, even if it is only for your self or your team.

On https://nuget.org/ you can find more information on this Visual Studio plugin as well as information on how to create and upload packages. I have published my VsDoc file using NuGet so it is available there. Below is a short description on how you can publish you own libraries. This information is all available on the nuget site but spread out a bit.

First you will need to download the package builder (http://docs.nuget.org/docs/creating-packages/using-a-gui-to-build-packages). There also is a command line version available which can be used as part of a build process. The GUI version is deployed using ClickOnce deployment to ensure you have the latest version.

Create a Package

In the application Create a new package. First thing to define is the metadata this can be done from the Edit menu. After saving this you will need to add the content files. This can simply be done by dragging the files into the package contents window. In the package contents you must use folder to determine where the files are deployed. The following folders are available:

  • Content
    Items in this folder are added to the project on deployment
  • Lib
    This folder can contain assemblies which are added as references to the project. Multiple version for different frameworks are supported (more details)
  • Src and Tools
    Not really sure what happens with the contents of these folders

More information on creating packages and package conventions can be found on the nuget website.

Testing

After defining the package and its content you can test the package. To do this:

  • Store the package in a local file folder.
  • In visual studio open the package manager settings (Tools menu, Library Package Manager)
  • Under package source add a name and the full path to the directory containing the package. Then click add
  • Now you can install the package (Tools menu, Library Package Manager, Manage NuGet Packages for Solutions ...)
  • Select Online on the left side and select your newly created source
  • A list showing all the packages in the folder will be displayed
  • Click install to deploy

Deploying

After testing you can if you desire publish you package to the nuget online repository. This can simply be done using the publish option in the file menu of the Package Builder. You will need an API key which you can obtain by creating an account on the nuget site.
Note: When publishing you need to untick the 'Use v1 protocal for this url' box otherwise you will get a 404 error.

Final remarks

One of the advantages of this plugin is that it allows you to easily add/remove and update commonly used resources to your applications.


Add Comment