# Xamarin Components and NuGet

Xamarin Studio 5.5 and Xamarin for Visual Studio 3.7 have support for Xamarin Components with NuGet package dependencies. So you can now have Xamarin Studio or Visual Studio add NuGet packages to a project when a Component is installed from Xamarin’s Component Store.

The NuGet Support in Xamarin Studio 5.5 post looked at installing a Component with a NuGet package dependency into a project but did not cover how to create one of these Components. So let us take a look at how to modify an existing Component so it has NuGet package dependencies.

## Adding a NuGet Package Dependency to a Component

In this section we will look at modifying a Component so when it is installed it adds NuGet packages to the project as well as referencing the assemblies that are included in the Component.

The downloaded xpkg file is a zip file containing xamarin-component.exe. So rename the file to have a .zip file extension and then extract the executable.

Now let us see how to add a single NuGet package dependency to the Component. If you are using a component.yaml file to generate your Component you can add the NuGet package dependency by adding the following to your component.yaml:

packages:
"": Newtonsoft.Json, Version=5.0.8


With the above defined in your component.yaml file you can run the xamarin-component.exe package command to generate your Component’s .xam file.

Windows:

xamarin-component.exe package path\to\directory-with-component-yaml


Mac:

mono xamarin-component.exe package path/to/directory-with-component-yaml


If you then look inside your generated Component file (.xam), which you can do by renaming its file extension to .zip, you will see the package defined in the component/Manifest.xml file:

<packages>
<package id="Newtonsoft.Json" version="5.0.8" />
</packages>


If you are using the xamarin-component.exe create-manually command line you can add the same NuGet package dependency by adding the following command line argument:

--package="":"Newtonsoft.Json, Version=5.0.8"


This packaged Component will install the Newtonsoft.Json NuGet package into any Android, iOS or Windows Phone project. If you need to install a particular NuGet package for a particular project type you can specify the target project type for the NuGet package dependency. Shown below is a more complicated example from a component.yaml file where NUnit and Newtonsoft.Json are configured so they will only be installed into Android projects, whilst log4net is only installed into iOS projects, and finally Ninject will be installed into all project types.

packages:
android:
- NUnit, Version=2.6.2
- Newtonsoft.Json, Version=5.0.8
mobile: Ninject, Version=3.2.0
ios: log4net, Version=2.0.0
ios-unified: log4net, Version=2.0.0


Note that mobile used here is equivalent to the empty double quoted string “” which was used in the previous example with the single NuGet package.

If you then generate the Component again using the xamarin-component.exe package command you will see the Component’s manifest file now contains the following:

  <packages>
<package id="NUnit" version="2.6.2" framework="android" />
<package id="Newtonsoft.Json" version="5.0.8" framework="android" />
<package id="log4net" version="2.0.0" framework="ios" />
<package id="log4net" version="2.0.0" framework="ios-unified" />
<package id="Ninject" version="3.2.0" framework="mobile" />
</packages>


If you are using the xamarin-component.exe create-manually command line you can add the same NuGet package dependencies to your Component by adding the following command line arguments:

--package="android":"NUnit, Version=2.6.2"
--package="android":"Newtonsoft.Json, Version=5.0.8"
--package="mobile":"Ninject, Version=3.2.0"
--package="ios":"log4net, Version=2.0.0"
--package="ios-unified":"log4net, Version=2.0.0"


With the NuGet package dependencies defined as shown in the previous examples when you install the Component into a project the NuGet package will be installed and a reference will be added to the assemblies in the lib directory of the Component. If you want to only add the NuGet package to the project and not the assemblies in the lib directory then you can create a Shell Component which we will look at in the following section.

## Creating a Shell Component

A Shell Component is special type Component that is basically a wrapper around one or more NuGet packages. It will only install the NuGet package into the project and not add references to any assemblies in the Component’s lib directory.

To configure a component to be a Shell Component you can add the following to your component.yaml file:

is_shell: true


When you generate your Component’s .xam file you will see that the Component’s Manifest.xml file now contains the is-shell attribute in the component element:

<component format="1" id="mycomponent" is-shell="true">


If you are using the xamarin-component.exe create-manually command line argument you can do the same thing by passing the following argument:

--is-shell


Backwards compatibility is something to consider if you decide to create a Shell Component. If you need a Shell Component to work with older versions of Xamarin Studio and Xamarin for Visual Studio that do not support Component’s with NuGet package dependencies then you should also include the assemblies in the lib directory of the Component. The Android Support Library v13 Component is one example that has a NuGet package dependency and also includes an assembly in its lib/android directory. When installing the Android Support Library v13 Component into an older version of Xamarin Studio the NuGet package will not be installed and instead the assembly will be referenced from the Component’s lib/android directory. If the Android Support Library v13 Component is installed with Xamarin Studio 5.5 or above then the NuGet package will be installed but the assembly from the lib/android directory will not be referenced.

## NuGet Package Sources

The NuGet package dependencies that a Component has must be available from the official NuGet Gallery before your Component is submitted to the Component Store.

If you are testing a NuGet package that is not currently available from the official NuGet Gallery then you can copy it into the local machine’s NuGet cache directory. Xamarin Studio and Xamarin for Visual Studio should find the NuGet package in the local NuGet cache instead of trying to download it from the NuGet Gallery.

## Creating a Component

There are some example Component’s that have NuGet package dependencies available on my GitHub page. The Awesome Component example is a Shell Component that uses a rakefile and the xamarin-component create-manually command line to generate the Component. The My Component example is another Shell Component that uses a component.yaml file that defines NuGet package dependencies.

For more detailed information on how to create a Component please see the Submitting Components page.

# NuGet Support in Xamarin Studio 5.5

## New Features

• Package version constraints in packages.config files are now supported
• Xamarin Components can now have NuGet package dependencies

More information on all the new features and changes in Xamarin Studio 5.5 can be found in the release notes.

## NuGet Package Version Constraints

NuGet allows you to define a range of package versions that are allowed in your project using the allowedVersions attribute in the packages.config file.

<packages>
<package id="Newtonsoft.Json" version="5.0.1" allowedVersions="[5.0,6.0)" targetFramework="MonoAndroid44" />
</packages>


In the above packages.config file the project has Json.NET 5.0.1 installed and will only allow updates to versions of Json.NET that are below 6.0.

When you open the solution in Xamarin Studio, and check for updates is enabled in preferences, you will see updates in the Solution window that are valid given the constraint defined in the packages.config file. In the screenshot below an update is shown for Json.NET 5.0.8 in the Solution window even though Json.NET currently has version 6.0.5 available.

When you update the NuGet packages from the Solution window Xamarin Studio will now update to a NuGet package that meets the version constraints defined in the packages.config. In the Package Console screenshot below the Json.NET package was updated, with the constraint in place, and Json.NET 5.0.8 was installed.

Note that if you install a NuGet package from the Add Packages dialog you can override the constraint and install a NuGet package with a version outside of the range of the constraint.

## Components with NuGet Packages

A Component from Xamarin’s Component Store can now declare a dependency on one or more NuGet packages which will be installed into the project when the Component is installed. The Android Support Library v13 Component is one example that has a NuGet package dependency.

When you install this Component you will see that it installs the Xamarin.Android.Support.v13 NuGet package.

In older versions of Xamarin Studio the NuGet package will not be installed and instead the project will reference the Xamarin.Android.Support.v13.dll which is included with the Component.

The NuGet packages a Component depends on are displayed in the Packages tab on the Component Details page, which you can open by double clicking the Component in the Solution window, or by right clicking the Component and selecting Details.

From the Packages tab you can also install a NuGet package that a Component depends on if it was removed from the project. So if the Xamarin.Android.Support.v13 NuGet package is removed from the project the Component will be highlighted in red to indicate that there is a problem.

If you then open the Component Details page you will see in the Packages tab that the NuGet package is missing.

To add the NuGet package back to the project you can hover the mouse over the warning icon and click the Add Package button that appears in the pop-up window.

# NuGet Support in Xamarin Studio 5.4

## New Feature

• Added support for the new Unified target frameworks for iOS and Mac
• Xamarin.iOS
• Xamarin.Mac

More details on all the new features and changes in Xamarin Studio 5.4 can be found in the release notes.

## New Unified iOS and Mac Target Frameworks

Xamarin recently announced a new Unified API for its iOS and Mac products. This new Unified API makes it easier to share code between Mac and iOS as well as allowing you to support 32 and 64 bit applications with the same binary.

To use this new Unified API you can create a new Unified project for iOS, or for Mac, using one of the project templates available from Xamarin Studio’s New Project Dialog.

These Unified projects now support MSBuild and use the following target frameworks:

• Xamarin.iOS
• Xamarin.Mac

## NuGet Support for the New Unified Target Frameworks

In order to support these two new frameworks the following changes were made to NuGet.

• Add Xamarin.iOS and Xamarin.Mac as known frameworks.
• Make frameworks that have a name that starts with Xamarin optional when checking the compatibility of Portable Class Libraries (PCLs) inside a NuGet package with a Portable Class Library project.

With these new Unified frameworks being recognised by NuGet you can now create a NuGet package with assemblies that specifically target these frameworks. The following shows part of a .nuspec file with framework specific assemblies for iOS and Mac being copied into the appropriate target lib folder inside the NuGet package.

<files>
<file src="lib\Xamarin.iOS\*.dll" target="lib\Xamarin.iOS10" />
<file src="lib\Xamarin.Mac\*.dll" target="lib\Xamarin.Mac20" />
</files>


The Splat NuGet package, created by Paul Betts, is one NuGet package available from the main NuGet gallery that explicitly targets both of the new Unified frameworks.

Having the Xamarin frameworks treated as optional by NuGet allows you to install a NuGet package containing PCL assemblies into a Portable Class Library project, on a machine with the Xamarin PCL profiles registered. Without the Xamarin frameworks being treated as optional the NuGet package would fail to be installed since NuGet would find them incompatible unless the NuGet package explicitly included the Xamarin frameworks as part of its PCL profile.

Support for the new Xamarin frameworks will be available in the official NuGet from Microsoft in version 2.8.3. NuGet 2.8.3 is currently available as alpha release. Xamarin Studio 5.4 includes its own build of NuGet which has support for the new Xamarin frameworks.

## Portable Class Libraries

In order to be able to install a NuGet package containing PCL assemblies, such as Json.NET, into a Unified iOS or Unified Mac project you will need to have the PCL profile XML files for Unified iOS and Mac installed on your machine.

On the Mac you can get these new PCL profile XML files by installing Mono 3.10.0, which is currently available from Xamarin Studio on the alpha and beta channels.

On Windows, since NuGet 2.8.3 is currently only available as an alpha release, there is a separate installer which will register the Unified iOS framework with the PCL profiles on your machine and will also install an alpha version of Microsoft’s NuGet Package Manager 2.8.3 into Visual Studio.

# NuGet Support in Xamarin Studio 5.3

## Changes

• NuGet package restore is now part of Xamarin Studio and no longer uses NuGet.exe
• Add Packages dialog – Package sources could not be reached shown for failing package sources
• Packages restored for the selected project instead of the solution
• Show packages up to date message in status bar if there are no package updates available
• Show status bar warning message when no updates found and package sources are unavailable
• Restore missing packages before updating a package
• Do not check for updated packages if the project has no packages
• Fix empty source being selected in Add Packages dialog when package source disabled and All Sources selected
• Fix packages.config marked as deleted by Git when updating packages

More information on all the new features and changes in Xamarin Studio 5.3 can be found in the release notes. Now let us take a more detailed look at the new NuGet changes.

## NuGet package restore no longer uses NuGet.exe

The NuGet package restore is now a part of Xamarin Studio and no longer uses NuGet.exe. This allows the package restore to integrate with the Xamarin Studio credential provider and provides more control over the package restore process. So if a package source needs authentication, or uses a proxy, then Xamarin Studio will now show a dialog asking for credentials if the credentials are not stored. Previously the package restore would fail with an error message logged in the Package Console.

## Add Packages dialog – Package sources could not be reached

Previously when All Sources was selected and if any package source could not be reached then an error message would be displayed and no packages would be shown in the list. Now packages will be displayed with a warning even if one package source could not be reached.

## Packages restored for the selected project instead of the solution

Xamarin Studio will now restore packages for the selected project instead of the entire solution. When you right click the Packages folder in the Solution window and select Restore only the packages for that project will be restored.

This is now possible since Xamarin Studio is now responsible for restoring packages instead of using NuGet.exe which would only restore for the entire solution.

To restore packages for the entire solution you can still use the Restore Packages menu which is available from the Project menu or by right clicking the solution in the Solution window.

Opening the Add Packages dialog will now show the packages added to all projects in the current solution.

The order of the items displayed in the Add Packages dialog is recent packages first, then solution packages, and then the packages from the active package source.

## Show packages up to date message in status bar if there are no package updates available

When you try to update a package and there are no package updates available then the status bar now displays a message indicating that the package is already up to date.

Similarly if you update multiple packages and there are no updates available then the status bar will now show a packages are up to date message.

Previously the status bar would show a message that the package was updated successfully even if nothing was updated.

## Show status bar warning message when no updates found and package sources are unavailable

When one or more of the package sources is unavailable or invalid then Xamarin Studio will now report a warning in the status bar after checking for updates.

## Restoring missing packages before updating packages

Previously when NuGet packages were unrestored and an attempt was made to update a NuGet package, which had updates available from the package source, the update would fail with a message indicating that the package was installed successfully but the project did not reference the package.

To prevent the update from failing Xamarin Studio will now check that the packages are restored for the project before trying to update and restore any missing packages. In the status bar a Restoring packages before update message will be displayed when a restore must be completed first.

## Bug Fixes

Do not check for updated packages if the project has no packages

Xamarin Studio was checking for package updates in all projects even if they had no packages.config file when the solution was opened. This would result in the Packages are up to date message being displayed in the status bar even when no projects were using any NuGet packages.

Now if the project has no packages.config file then Xamarin Studio will not check for updates.

When running a package version search, such as Xamarin.Forms version:*, the right hand side of the dialog was showing the version number instead of the download count.

Now the dialog shows the download count. Ideally it would show the download count of that particular version but this is not currently available from the Package object returned by NuGet. It is returned in the results back from the package source but it is not available on the Package object.

Also the download counts are different for the same package if you compare the normal search result with a package version search result. The package version search shows a larger download count number. This may be related to the stats problem NuGet had recently. Currently Xamarin Studio is showing the download count it receives. The standard search download counts match those shown in Visual Studio’s Manage Packages dialog. For the package version search the download count value matches that shown on the NuGet.org website for an individual package (e.g. https://www.nuget.org/packages/jQuery).

Fix empty source being selected in Add Packages dialog when package source disabled and All Sources selected

An empty package source selected in the Add Packages dialog could occur when All Sources was selected in the Add Packages dialog and one of the enabled package sources was unchecked in Preferences. On opening the Add Packages dialog again an empty package source would be displayed as the selected package source.

Now the Add Packages dialog will have the remaining enabled package source selected.

Fix packages.config marked as deleted by Git when updating packages

On updating packages in a project, and the project is using Git for version control, then the update was causing Git to show the packages.config file as deleted. This would occur if all the NuGet packages were uninstalled as part of the update which caused NuGet to see that there were no NuGet packages referenced and delete the packages.config file.

Now the packages.config file is shown as modified instead of deleted.

# NuGet Support in Xamarin Studio 5.2

## New Features

• Automatic package update check
• Package framework retargeting
• Support for custom packages directory in NuGet.Config
• Add all checked packages even if they are not visible

More details on all the new features and changes in Xamarin Studio 5.2 can be found in the release notes. Now let us take a more detailed look at the new NuGet features.

## Automatic package update check

On opening a solution Xamarin Studio will check in the background for updated packages used by your projects. When the update check begins the status bar will show a Checking for package updates message.

If Xamarin Studio finds there are new updated packages available then the status bar will show a Package Updates are available message.

The Solution window will show information about the updates in the Packages folder.

The Packages folder will show the number of updated packages available for a project. For each package inside the Packages folder you can see the version number for the update.

Note that Xamarin Studio will only show updates that are for non-pre-release packages.

The automatic package update feature can be disabled in Preferences by unchecking Check for package updates when opening a solution.

## Framework retargeting

A NuGet package will often contain assemblies for several target frameworks. Json.NET, for example, contains assemblies for:

• .NET 2.0
• .NET 3.5
• .NET 4.0
• .NET 4.5
• .NET Core 4.5 (Windows Store)
• Portable Class Library (PCL)
• .NET 4, Silverlight 5, Windows Phone 8, Windows 8, Windows Phone Application 8.1
• Portable Class Library (PCL)
• .NET 4.5, Windows Phone 8, Windows 8, Windows Phone Application 8.1

When you install this NuGet package into your project the assembly that is referenced is determined by your project’s target framework. NuGet will reference the assembly which it considers to be the best match for your project’s target framework. So if you install Json.NET into a project that targets .NET 4.5 the Json.NET assembly referenced will be taken from the .NET 4.5 folder inside the NuGet package.

If you change your project’s target framework after you have installed the NuGet package your project may be referencing a different assembly compared with what would have been referenced if you had installed it after changing the project’s target framework. In some cases the project’s target framework may not be compatible with the NuGet package. For example, your project targeted .NET 4.5 and you then changed it to .NET 2.0. In this case you would be referencing a .NET 4.5 assembly that would not work with .NET 2.0. Another example is if you change the PCL profile of your project which could affect which PCL assemblies are used from the NuGet package.

In Xamarin Studio 5.2 if you change your project’s target framework then the NuGet packages referenced by your project are checked to see if they are still compatible. The result of this check is displayed in the Package Console.

In the screenshot above the project’s target framework was changed from .NET 4.5 to .NET 2.0 whilst the project had the Json.NET and Moq NuGet packages installed. Json.NET is compatible with .NET 2.0 and can be retargeted. Moq does not support .NET 2.0 and is not compatible.

To retarget an individual NuGet package you can select the package in the Solution window, right click and select Retarget.

To retarget all packages in the project you can select Packages in the Solution window, right click and select Retarget.

Selecting Retarget will remove the NuGet package and then add it again so the correct assembly is referenced by your project. The status bar will be updated as the package is retargeted and full details can be seen in the Package Console.

The Retarget menu item is only available if NuGet packages need to be retargeted.

Note that if you retarget a NuGet package that is incompatible with your project’s target framework then the retargeting will fail and the NuGet package will be removed from the project.

## Support for custom packages directory in NuGet.Config

When a NuGet package is installed into a project the NuGet packages are by default downloaded into a packages directory inside the solution directory. The location and name of this packages directory can be configured by specifying the repositoryPath in the NuGet.Config file.

<configuration>
<config>
</config>
</configuration>


If you create a NuGet.Config file and put it the .nuget directory inside the solution, or in the solution’s directory, then Xamarin Studio will read the repositoryPath and use it when downloading NuGet packages. The path is relative to the NuGet.Config file but you can specify a full path if you need to.

Note that if you make a change to the repositoryPath whilst the solution is open you will need to close and re-open the solution for the changes to be detected.

## Add all checked packages even if they are not visible

The Add Packages dialog will now add all packages that were checked when you click the Add Packages button even if they are not currently being displayed in the dialog. This allows you to run multiple searches in the dialog, check multiple packages and then add them to the project in one step without having to open the Add Packages dialog multiple times. Previously only the checked packages that were displayed in the list of packages would be added to your project.

## Bug Fixes

Incorrect path separator used for MSBuild Import

A NuGet package can contain custom MSBuild .targets and .props files. Previously when a NuGet package was installed on the Mac a forward slash path separator was used when adding the paths for custom MSBuild .targets file. This would cause Xamarin Studio on Windows to fail to compile the project. Now backslashes are used for all paths added to the project file.

Xamarin Studio will also now add a Condition to the project file that checks the imported MSBuild .targets file exists. Without this condition the project cannot be opened in Visual Studio if the NuGet packages are missing.

As an example, if Xamarin.Forms 1.1.1.6206 is installed into a project the following Import element will be added.

<Import
Project="packages\Xamarin.Forms.1.1.1.6206\build\portable-win+net45+wp80+MonoAndroid10+MonoTouch10\Xamarin.Forms.targets"
Condition="Exists('packages\Xamarin.Forms.1.1.1.6206\build\portable-win+net45+wp80+MonoAndroid10+MonoTouch10\Xamarin.Forms.targets')" />


Repositories.config not restored

When NuGet packages were restored for the solution the repositories.config file was not being restored. The repositories.config file contains references to all the projects in the solution that have NuGet packages. This information is used by NuGet to determine whether a NuGet package can be removed from the packages directory when a NuGet package is removed from a project. Without this information a NuGet package that is still referenced by other projects could be removed from the packages directory and cause the compilation to fail.

Package Dependencies not resolved from enabled package sources

Xamarin Studio will now use all enabled package sources when resolving dependencies for a NuGet package even if a single package source is selected in the Add Packages dialog. This allows the use of a NuGet package source that has packages that have dependencies that are not available from that particular package source but are available from another package source.

Packages are up to date status bar message

If you have the automatic check for updates disabled and update one or more NuGet packages the status bar will now display a message indicating that the packages are up to date if there are no updates available. Previously Xamarin Studio would show a message that the packages were updated when they were not.

Updating an unrestored package

If you have automatic package restore disabled and you attempt to update a NuGet package the package will now be restored before the update is attempted. Previously this would fail when an update was available since NuGet looks at the old package to work out how to remove it from the project before updating to the new NuGet package.

# NuGet Support in Xamarin Studio 5.1

Xamarin Studio 5.1 was released last week and it includes some new features for the NuGet addin.

## New Features

• Searching and installing a specific version of a NuGet package.
• Support for NuGet package sources defined in a solution specific NuGet.Config file.

More details on all the new features and changes in Xamarin Studio 5.1 can be found in the release notes. Now let us take a look at the new NuGet features.

## Searching and installing a specific version of a NuGet package

The Add Packages dialog can now be used to search and install a specific version of a NuGet package. You can search for all versions, a range of versions, or a specific version of a NuGet package. To do this the following search syntax is used:

PackageId version:VersionNumber


The packages are shown in the Add Packages dialog with the most recent version at the top. At the top right of each package in the package list you will see the package version instead of the download count allowing you to find the particular version you want to install.

To search for all versions of the AutoMapper NuGet package you can use an asterisk or leave the version number blank.

AutoMapper version:*


To search for all the 2.1 versions of the AutoMapper NuGet package you can use the search:

AutoMapper version:2.1


This will return a range of versions from 2.1.0 up to but not including 2.2.

The package id used in the search must match the id of the NuGet package otherwise no results will be returned.

Searching for package versions is also supported in the universal search at the top right of Xamarin Studio.

## Package sources defined in a solution specific NuGet.Config file

If package sources are defined in the solution’s NuGet.Config file then these will be available in the Add Packages dialog when this solution is opened. The NuGet.Config file can be in the solution directory or in the .nuget subdirectory. An example NuGet.Config file is shown below.

<configuration>
<packageSources>
<add key="ASP.NET vNext - MyGet" value="https://www.myget.org/F/aspnetvnext/" />
</packageSources>
</configuration>


When the solution is opened the package sources defined in the NuGet.config file are available in the drop down list at the top left of the Add Packages dialog.

## Bug Fixes

Proxy credentials not being requested for a https package source.

Added a workaround to NuGet to handle Mono returning a different http response when proxy authentication is required.

Web.config transforms not being applied when installing NuGet packages such as Nancy.Hosting.Aspnet.

Projects were not being recognised as web projects so transforms were only being applied to app.config files.

XDT remove transforms (Xml Document Transformations) failing on Mono.

Modified the XDT library that ships with Xamarin Studio to handle different behaviour on Mono compared with Microsoft’s .NET Framework. These transforms are used in the Microsoft.AspNet.Mvc NuGet package.

# NuGet PowerShell Console for Xamarin Studio

Xamarin Studio 5.0 now has NuGet support built in. There are also some experimental NuGet features that are available for Xamarin Studio 5.0 and MonoDevelop 5.0 as part of a separate NuGet extensions addin. One such experimental feature is a new PowerShell console window that provides Xamarin Studio with the standard NuGet commands and also works on the Mac, not just Windows.

The new console window is powered by Pash. Pash is a open source reimplementation of PowerShell that works with Mono and runs on Windows, Mac and Linux. It was created by Igor Moochnick and more recently development has been restarted by Jay Bazuzi.

## PowerShell Console Features

• Standard NuGet PowerShell commands available – Install-Package, Update-Package, Uninstall-Package, Get-Project and Get-Package
• Integrates with the existing NuGet addin that ships with Xamarin Studio.
• Cross platform – works on Windows and Mac.
• Partial implementation of the Visual Studio object model EnvDTE.

## Limitations

• PowerShell support is not fully implemented in Pash so PowerShell scripts may not fully work.
• Xamarin Studio needs to be closed and re-opened before the console can be used. Otherwise the Xamarin Studio will crash.
• Some standard parameters are missing from the NuGet commands (e.g. -verbose).
• The NuGet commands are not fully up to date compared with the commands available in Visual Studio. One example is Update-Package -Reinstall which is currently not supported.

## Installation

• Open the Add-in Manager dialog.
• Select the Gallery tab.
• Select Xamarin Studio Add-in Repository (Alpha channel) from the drop down list.
• Expand IDE extensions.
• Select NuGet Package Management Extensions.
• Click the Refresh button if the addin is not visible.
• Click Install… to install the addin.

Please close and re-open Xamarin Studio before trying to open the PowerShell Console window otherwise Xamarin Studio will crash.

## Using the PowerShell Console

To open the console window, from the View menu select Pads and then select Package Console Extension.

The top of the console window has drop downs allowing you to choose a different default package source or default project. At the top right there is a Clear Console button which will clear all the text from the console.

The standard NuGet PowerShell commands are available from the console window:

• Install-Package
• Uninstall-Package
• Update-Package
• Get-Package
• Get-Project

There is also a partial implementation of the Visual Studio object model (EnvDTE) which you can use from the console and from PowerShell scripts inside a NuGet package. Currently the Solution object and the CodeModel is not fully implemented when compared with SharpDevelop.

When you install a NuGet package from the console and the NuGet package has an init.ps1 or an install.ps1 PowerShell script then these scripts will be run. Similarly on uninstalling a NuGet package if it contains an uninstall.ps1 script then this will be run in the console. However there are some areas of PowerShell that are not fully implemented in Pash so the script may well fail. The failure will be logged in the console window but it will not prevent the package from being installed or uninstalled.

That concludes the introduction to the experimental NuGet Package Console in Xamarin Studio.

# NuGet Support in Xamarin Studio 5.0

Xamarin Studio 5.0 was released last week as part of the Xamarin 3.0 release and it now has built-in support for NuGet. There is no need to install the NuGet addin separately into Xamarin Studio 5.0 or MonoDevelop 5.0 since it is now “in the box”.

## New Features

• Re-designed user interface.
• More integrated with the Solution window.
• Supports NuGet’s search syntax.
• Background package installation.
• Integrates with Xamarin Studio’s unified search.
• Support for NuGet packages in project templates.
• Package restore on opening a solution.
• Integrates with Xamarin Studio’s credential provider to provide proxy and package source authentication.

So let us a look at these features in more detail by looking at how to use the NuGet addin in Xamarin Studio 5.0.

To add a NuGet package we need to open the Add Packages dialog. This can be done in the following ways:

• From the Project menu select Add Packages. The project will need to be selected in the Solution window.
• From the Solution window, right click the project and select Add – Add Packages.

• From Xamarin Studio’s unified search, available in the top right of the main window, enter the name of the package you would like to search for, then select Search Packages.

• Double clicking the Packages folder in the Solution window will also open the Add Packages dialog (note the Packages folder is only displayed if you have a NuGet package installed in your project).

On opening the Add Packages dialog you will see a re-designed user interface.

If a NuGet package has an associated image then it will now be displayed in the list of packages.

The search text box at the top right of the dialog will now search for packages as you type.

The package source combo box at the top left of the dialog now includes a new Configure Sources item which allows you to quickly switch to the configured package sources in preferences and back again to the Add Packages dialog.

The list of packages now has infinite scroll support. As you scroll down the list new packages will be retrieved from the package source and displayed. Previously you had to click a button to move to the next page.

To install a NuGet package in the Add Packages dialog you can do one of the following:

• Select a package and double click it.
• Select a package and press the enter key.
• Select a package and press the Add Package button.

To install two or more NuGet packages you can click the check box next to the package and then select the Add Packages button.

On adding the NuGet package the Add Packages dialog will close and the package installation will complete in the background. You will see status messages appear in the status bar at top of the main window as the installation progresses. The screenshots below show the status messages that are displayed when the NUnit NuGet package is installed.

More detailed information about the installation can be seen in the Package Console window.

The Package Console can be opened by clicking on a package status message in the status bar or from the View menu by selecting Pads – Package Console. If there is an error when installing a NuGet package then the Package Console will automatically open to show more information about the error.

On adding the first NuGet package to a project a Packages folder will be displayed in the Solution window.

Any assembly references that a NuGet package adds to your project will be displayed in the From Packages folder inside References.

Whilst the NuGet package is being installed the package id text will be highlighted.

After the NuGet package is installed the text will be changed to black and a status message will be shown in the status bar.

## Searching for Packages

The Add Packages dialog now supports the extended NuGet search syntax. Note that the NuGet package source will need to support this syntax. The main NuGet.org package source supports this search syntax.

So you can now make your search more specific by using one of the special tags, such as id, packageid, tags, author or owner. Some example searches are shown below:

id:NUnit
packageid:Xamarin.Forms
tags:typescript
owner:xamarin
author:xamarin


## Removing NuGet Packages

You can remove a NuGet package from the Solution window. Expand the Packages folder for your project, select the package, right click and select Remove, or press the delete key.

The package will then be uninstalled in the background. Status information will appear in the status bar and more detailed information will be shown in the Package Console window.

## Updating NuGet Packages

You can update an individual NuGet package by selecting it in the Solution window, right clicking and selecting Update.

You can update all the packages in a project by right clicking the Packages folder and selecting Update.

To update all the packages in the solution, either right click the solution in the Solution window and select Update Packages, or from the Project menu select Update Packages.

As with adding and removing a NuGet package you will see status bar messages as the update progresses and detailed information in the Package Console window.

## Restoring NuGet Packages

By default NuGet packages will be automatically restored when a solution is opened.

You can disable this by going into preferences and unchecking Automatically restore packages when opening a solution.

With automatic package restore disabled you can manually restore NuGet packages in the following ways:

• Right click the Packages folder in the Solution window and select Restore.
• Right click the solution and select Restore Packages.
• From the Project menu select Restore Packages.

The status bar will be updated with information on the progress of the restore. More detailed information can be seen in the Package Console window.

## NuGet Packages in Project Templates

You can now have a project template that will install NuGet packages. To do this you add a Packages element inside the Project element of the project template.

<Packages>
<Package id="NUnit" />
<Package id="jQuery" version="1.7.1" />
</Packages>


You can specify an exact version for the NuGet package. If the version is not specified then the latest version of the NuGet package will be installed.

By default Xamarin Studio will look for the NuGet packages from the main NuGet.org package source. To use your own package source instead you can create an addin and define the package source in its .addin.xml file. Inside your .addin.xml file you can add an Extension element which supports both online NuGet package sources and local directory package sources.

To define an online NuGet package source you can use the url attribute in your .addin.xml file:

<Extension path = "/MonoDevelop/Ide/ProjectTemplatePackageRepositories">
<PackageRepository url="https://mynugetfeed.nget/packages" />
</Extension>


<Extension path = "/MonoDevelop/Ide/ProjectTemplatePackageRepositories">
<PackageRepository path="packages" />
</Extension>


The path attribute here should contain the directory relative to where the addin is installed.

## Package Source and Proxy Authentication

If a NuGet package source or a proxy needs authentication then Xamarin Studio will prompt for credentials.

Please note that there is a bug that currently prevents proxy authentication with package sources that use https which will be fixed in the next release of Xamarin Studio.

## Configuring NuGet Package Sources

NuGet package sources can be configured in preferences.

A new feature here is the ability to specify a username and password for a package source that requires authentication. The username and passwords are encrypted and stored in the NuGet.config file in the same way that NuGet.exe will if you use it on the command line.

That concludes our look at the new NuGet features in Xamarin Studio and MonoDevelop 5.0

# MonoDevelop NuGet Addin 0.9 Released

A new version of the NuGet addin for Xamarin Studio and MonoDevelop has been released.

## New Features

The main change is to include NuGet 2.8.1 which adds support for Windows Phone 8.1 projects. Also some of the newer NuGet packages, such as Microsoft.Bcl.Immutable 1.1.20-beta, which the Roslyn NuGet packages depend on, will not install unless NuGet 2.8.1 is being used.

For a detailed look at the changes please read the release note.

# MonoDevelop NuGet Addin 0.8 Released

A new version of the NuGet addin for Xamarin Studio and MonoDevelop has been released.

## New Features

The main change is support for NuGet 2.7.2 so you can now add NuGet packages, that include Portable Class Libraries (PCLs), to projects that target MonoAndroid.

For a detailed look at the changes please read the release note.