NuGet is a package management system for .NET that simplifies the process of using third party libraries in your application. It provides access to over 20,000 third party libraries which are available from the main NuGet package gallery.
Microsoft are also embracing NuGet. Microsoft use NuGet as one of the primary ways to release libraries and have their own curated NuGet package feed.
Xamarin is also using NuGet to distribute libraries. Xamarin.Forms, the new library which allows you to build native UIs for iOS, Android and Windows Phone from a shared C# codebase, is available to download from NuGet and install into your application.
Thousands of libraries are available from NuGet, many of these are compatible with Xamarin’s frameworks, that can be used in your iOS, Android, Mac and Windows applications. There are also an increasing number of NuGet packages that contain Portable Class Libraries (PCLs), that are compatible across a range of desktop and mobile frameworks. All of these libraries are now easily available to you from within Xamarin Studio.
Xamarin Studio NuGet Features
- Search across thousands of third party libraries available as NuGet packages.
- Quickly add NuGet packages to your application and start using them.
- Easily update a single package or all packages to their latest versions.
- Automatically restore packages on opening your solution.
- Project templates can install NuGet packages when a new project is created.
- Consume packages from other third party NuGet package sources.
- Search for NuGet packages from the universal search.
- Deep integration with Xamarin Studio – integrates with the Solution window, the status bar and the universal search.
Now let us take a look at some of these Xamarin Studio features starting with adding a NuGet package to a project.
Adding a NuGet Package
With your project open in Xamarin Studio, from the Solution window, right click the project and select Add – Add Packages.
This will open the Add Packages dialog showing you a list of NuGet packages available from the main NuGet gallery.
From this dialog you can search for NuGet packages and quickly add them to your project. Once you have found a package you can install it by simply selecting it and double clicking or by clicking the Add Package button. The dialog will then close and Xamarin Studio will install the NuGet package in the background. As the install proceeds Xamarin Studio’s status bar will be updated with progress messages.
Detailed information on what happened during the install can be seen in the Package Console window.
The Solution window will display a Packages folder which contains all the packages installed in the project.
From the Packages folder you can easily update a package to the latest version, or remove it from the project, by right clicking and selecting the appropriate menu item.
Assembly references added to the project by the NuGet package are displayed inside the From Packages folder in the Solution window.
Restoring NuGet packages
Xamarin Studio will automatically restore any NuGet packages that are missing when a solution is opened. This means you do not need to add NuGet packages to your source control system. Only the packages.config file for each project needs to be added to your source control system. When another developer opens the solution for the first time all the missing NuGet packages will automatically be downloaded and restored by Xamarin Studio.
In the screenshot above the Xamarin.Forms button source code sample, which uses NuGet packages, was opened in Xamarin Studio and the NuGet packages were automatically restored.
Project Templates with NuGet Packages
Project templates now have support for NuGet packages so Xamarin Studio can install NuGet packages when a new project is created. The project templates for Xamarin.Forms takes advantage of this feature and will install NuGet packages when a new Xamarin.Forms project is created.
This is the end of our introduction to the NuGet support in Xamarin Studio. If you would like to learn more about Xamarin Studio then here are some more resources.
- Overview of Xamarin Studio features
- Say Hello to Xamarin 3 webinar video
- Walkthrough: Including a NuGet package in your project
- In depth look at NuGet support in Xamarin Studio