Matt Ward

NuGet Support in Xamarin Studio 6.0

Xamarin Studio 6.0 was released last week and it includes a lot of new features, such as a new dark theme and Roslyn integration. This release also includes some improvements made to the NuGet support.

Add Packages Dialog - Dark Theme

New Features

  • Support NuGet packages targeting tvOS.
  • Support updating pre-release NuGet packages.
  • Show updates available for pre-release NuGet packages.
  • Remember Show pre-release Packages setting in Add Packages dialog.
  • Error dialog displayed if NuGet.Config file cannot be read.

More information on all the changes in Xamarin Studio 6.0 can be found in the release notes.

Support NuGet packages targeting watchOS

A new Xamarin.WatchOS target framework is now supported which allows NuGet packages to contain assemblies for watchOS.

Support updating pre-release NuGet packages

Previously it was not possible to update a pre-release NuGet package to a later pre-release from the Solution window, only updates to stable NuGet packages were supported. The only way to update to a later pre-release NuGet package was to use the Add Packages dialog.

Now an individual pre-release NuGet package can be updated by right clicking and selecting Update. When all packages in a project or solution are updated then pre-release NuGet packages will be updated to a later pre-release version if they are available.

Show updates available for pre-release NuGet packages

Previously Xamarin Studio would only show stable NuGet package updates as being available if a pre-release NuGet package was installed. Now Xamarin Studio will check for updates for pre-release NuGet packages as well as stable packages and display this information in the Solution window.

Pre-release NuGet package updates in Solution window

Only if an installed NuGet package is a pre-release version will pre-release updates be shown as available in the Solution window. Xamarin Studio will not check for pre-release updates for stable NuGet package versions that are installed.

Remember Show pre-release Packages setting in Add Packages dialog

The Show pre-release Packages check box setting will now be remembered in the Add Packages dialog on a per solution basis.

Error dialog displayed if the NuGet.Config file cannot be read

Previously if the NuGet.Config file could not be read the error would be silently logged, but not reported, and Xamarin Studio would then switch to using the default official NuGet package source. Now an error dialog is shown indicating that there was a problem reading the NuGet.Config file.

Bug Fixes

Support NuGet packages that use icons from local files

A NuGet package can now use an icon, which will be shown in the Add Packages dialog, taken from the local file system using a file url. Previously this would fail with an invalid cast exception.

Incorrect update count displayed after updating NuGet packages.

When an update caused a NuGet package to be uninstalled the Packages folder in the Solution window would show an incorrect count for the available updates.

NuGet restore and update not working for workspaces

With a workspace opened, or multiple solutions opened in Xamarin Studio, then restoring and updating NuGet packages would only work for one of the solutions.

Unable to add Google Play Services packages

The Xamarin.Android.Support.v7.AppCompat NuGet package depends on a single version of the Xamarin.Android.Support.v4 NuGet package. When a Xamarin Google Play Services NuGet package is installed that depends on a higher version of the Xamarin.Android.Support.v4 NuGet package the install would fail to find a version of the AppCompat NuGet package that is compatible. An error similar to the following would be displayed in the Package Console window:

Could not add Xamarin.GooglePlayServices.Ads.
Updating 'Xamarin.Android.Support.v4 23.1.1.0' to
'Xamarin.Android.Support.v4 23.1.1.1' failed. Unable to find a version
of 'Xamarin.Android.Support.v7.AppCompat' that is compatible with
'Xamarin.Android.Support.v4 23.1.1.1'.

The problem was that the AppCompat NuGet package is not involved in the initial NuGet package resolution using the remote package source so it is initially not considered for installation into the packages directory. When a package reference is then added to the packages.config file a search for a compatible AppCompat package was only using the local solution’s packages directory which fails causing the install to fail.

To fix this the local solution packages directory is used first when looking for a compatible AppCompat NuGet package and will fallback to using the configured remote package sources if no suitable package is found in this directory. To handle a package being added to the packages.config at this point, after the original NuGet packages have already been downloaded to the solution’s packages directory, Xamarin Studio will detect a package is added to the packages.config file and install the NuGet package if it is not already in the local solution packages directory.

Incorrect package version being installed

When installing a NuGet package using the Google Play Services dialog a package version is not specified by the dialog. If the NuGet package being installed was found in the local machine’s NuGet cache it would be used instead of the latest version from the official NuGet gallery at nuget.org. This could result in a lower version being installed than expected.

MSBuild property files (.props) not being added at correct project location

Installing a NuGet package that included an MSBuild .props file would add an Import element for the .props at the end of the project file (.csproj) instead of at the start. The .props files are now added to the project file as the first child element inside the project’s root element.

ASP.NET Core 1.0 RC2 support in Xamarin Studio

Xamarin Studio and MonoDevelop now have support for ASP.NET Core 1.0 RC2 with an alpha release of the .NET Core addin.

ASP.NET Core web project in Solution window

This is an update of the original DNX addin which adds support for .NET Core RC2 and also, thanks to David Karlaš, adds support for debugging .NET Core applications on the Mac.

Features

  • Debugging .NET Core applications with the .NET Core CLR on Mac.
  • Project templates for console, library and web applications
  • Code completion
  • NuGet integration
  • Solution window integration

Supports

  • MonoDevelop and Xamarin Studio 6.0 (build 5166). (Note that 6.1 is not yet supported)
  • .NET Core 1.0 RC2.

Installing .NET Core SDK

The .NET Core SDK needs to be installed separately before using the .NET Core addin. Detailed installation instructions can be found on Microsoft’s .NET Core web site.

Installing the addin

The addin is currently available from MonoDevelop’s Add-in Repository in the alpha channel. In Xamarin Studio open the Add-in Manager and select the Gallery tab. Click the repository drop down and if Xamarin Studio Add-in Repository (Alpha Channel) is not displayed then click Manage Repositories. In the window that opens tick the check box next to Xamarin Studio Add-in Repository (Alpha Channel) and then click the Close button.

.NET Core addin selected in Addin Manager dialog

Select the .NET Core addin and then click the Install button.

After installing the .NET Core addin you will need to restart Xamarin Studio before the project templates are available in the New Project dialog.

Creating a .NET Core project

There are three project templates available for .NET Core in the New Project dialog.

New ASP.NET 5 project templates

Debugging

Thanks to David Karlaš there is a support for debugging .NET Core applications when running on the .NET Core CLR if you have the VSCode Debugger addin installed.

Debugging a .NET Core application

The VSCode Debugger addin is currently available from MonoDevelop’s Add-in Repository on the alpha channel.

Debugging .NET Core console and web projects that target the full .NET framework is supported on all platforms. The .NET Core command line tool (dotnet.exe) will create an executable when targeting the full .NET Framework which can be debugged in Xamarin Studio. On Windows the x86 version of the .NET Core SDK needs be installed since Xamarin Studio currently cannot debug x64 applications on Windows.

Source Code

The source code for the addin is available on GitHub.

ASP.NET 5 and DNX support in Xamarin Studio

Xamarin Studio and MonoDevelop now have support for ASP.NET 5 and DNX with an alpha release of the DNX addin.

DNX web project in Solution window

The core part of the addin that communicates with the DNX host is taken directly from OmniSharp and is used mostly unchanged.

Features

  • Project templates for console, library and web applications
  • Code completion
  • Debugger support with Mono 4.3
  • NuGet integration
  • Solution window integration

Supports

  • MonoDevelop and Xamarin Studio 5.9 and later versions.
  • ASP.NET 5 RC 1 Update 1 and earlier versions.

Installing ASP.NET 5

ASP.NET 5 needs to be installed separately before using the DNX addin. There are instructions on get.asp.net on how to do this for Mac, Linux and Windows.

Installing the addin

The addin is currently available from MonoDevelop’s Add-in Repository in the alpha channel. In Xamarin Studio open the Add-in Manager and select the Gallery tab. Click the repository drop down and if Xamarin Studio Add-in Repository (Alpha Channel) is not displayed then click Manage Repositories. In the window that opens tick the check box next to Xamarin Studio Add-in Repository (Alpha Channel) and then click the Close button.

Enabling alpha channel addins

Back in the Add-in Manager dialog click the Refresh button to update the list of addins. Use the search text box in the top right hand corner of the dialog to search for the addin by typing in DNX.

DNX addin selected in Addin Manager dialog

Select the DNX addin and then click the Install button.

After installing the DNX addin you will need to restart Xamarin Studio before the project templates will be available in the New Project dialog.

Creating an ASP.NET 5 project

There are three project templates available for ASP.NET 5 in the New Project dialog.

New ASP.NET 5 project templates

Each of the project templates will create a solution and an .xproj file in the same way as Visual Studio 2015 does. The projects created should be compatible with Visual Studio 2015.

DNX console project in Solution window

Dependencies

When you create or open an ASP.NET 5 project the NuGet packages it uses will automatically be restored.

Restoring NuGet packages in Solution window

In the Solution window the dependencies show a warning icon if they are not resolved and the Dependencies folder shows a message that it is restoring the NuGet packages. Once restored you can expand the Dependencies folder and see the dependency hierarchy.

Dependency hierarchy in Solution window

If the DNX runtime being used by the solution is not installed then an error icon will be displayed next to the Dependencies folder.

Dependencies error icon in Solution window

Hovering the mouse over the error icon will show more information about the error.

Building

When you build the solution or project any errors and warnings are displayed in the Errors window and in the text editor. No assemblies are generated when you build.

DNX build error in text editor

DNX build errors in Errors window

Running

The main toolbar shows the currently selected command and the framework that will be used when the application is run. These are taken from the project.json file.

DNX commands in main toolbar

The screenshot above shows the main toolbar for a web project. There are three entries:

  • web
  • web DNX 4.5.1
  • web DNX Core 5.0

The first entry will run the web command and use the default runtime which will currently be DNX 4.5.1. The last two entries will run the web command but will explicitly run the application with the specified runtime.

Debugging

Thanks to David Karlaš and Zoltan Varga there is support for debugging DNX applications with DNX 4.5.1 if you have Mono 4.3 installed.

Debugging a DNX application

Debugging ASP.NET 5 projects with the CoreCLR is not supported on Mac nor on Linux. Debugging ASP.NET 5 projects is not supported at all on Windows.

Adding NuGet Packages

To add a NuGet package to a project you can right click the Dependencies folder in the Solution window and select Add NuGet Packages, or alternatively you can double click the Dependencies folder.

Add NuGet Packages menu in Solution window

This will open up the Add NuGet Packages dialog. Installing a NuGet package using this dialog will add the NuGet package into the project.json file.

Note that using the Add Packages dialog from the Packages folder will not add the NuGet package into the project.json file and will instead download the package to the packages directory and update the packages.config file.

Adding Dependencies

Dependencies can also be added directly into the project.json file. Currently there is no code completion available in the project.json file but changes to the file are monitored and the Dependencies folder will be updated when items are added or removed. New NuGet package dependencies that are added will automatically be restored if they are missing.

Removing Dependencies

A dependency can be removed by selecting it in the Solution window, right clicking and selecting Remove, or by pressing the delete key.

Remove dependency menu in Solution window

Changing the active framework

In Visual Studio the active framework can be changed by selecting it from the drop down list at the top of the text editor. Currently using the drop down list at the top of the text editor to change the active framework is not supported in Xamarin Studio. Instead you can right click in the text editor, select Active Framework and then select the framework.

Active DNX framework context menu in text editor

The active framework affects the code completion provided in the text editor. In the screenshot below the active framework has been set to DNX Core and you can see that the DateTime type does not show ToShortDateString in its completion list.

Code completion for active DNX framework

You can also see that the code in the #if DNX451 block is grayed out since it is not used with the currently active framework.

DNX Output

Output from the DNX host and from OmniSharp can be seen in the DNX Output window. This window can be opened by selecting DNX Output from the View menu.

DNX Output window

By default only warnings and errors will be displayed in the DNX Output window. To see more or less information you can change the DNX output verbosity in preferences in the DNX – General section.

Known Issues

kqueue() FileSystemWatcher has reached the maximum number of files to watch

When opening a project with many source files, such as AutoFac, you may see the above FileSystemWatcher error message. To resolve this problem you can set the MONO_MANAGED_WATCHER to false:

export MONO_MANAGED_WATCHER=false

Xamarin Studio will need to be run from the command line for this environment variable to be used.

project.json file formatting

When adding or removing dependencies from the Solution window will cause the project.json file to be reformatted differently compared to how Visual Studio 2015 formats the file.

Source Code

The source code for the addin is available on GitHub.

There is also a separate branch that supports MonoDevelop and Xamarin Studio 6.0.

NuGet Support in Xamarin Studio 5.10

Xamarin Studio 5.10 was released last week as part of the Xamarin 4 release and it includes changes to the NuGet support.

Changes

  • Support NuGet 2.8.7.
  • Open readme.txt when a NuGet package is installed.
  • Support packages.config file named after the project.
  • Local Copy settings are preserved for references when updating packages.
  • Do not show Checking for package updates message in status bar.
  • Do not show warning in the status bar if a NuGet package has PowerShell scripts.
  • Prevent the solution being closed when NuGet packages are being added.
  • Removing a NuGet package does not update the Solution window when multiple solutions are open.
  • Prevent packages.config file being marked as deleted by Git after updating a pre-release NuGet package.
  • Prevent retargeting a NuGet package marking packages.config as deleted by Git.
  • Allow Microsoft.ApplicationInsights NuGet package to be installed.
  • Support NuGet packages targeting watchOS.
  • Package license acceptance (Xamarin Studio 5.10.3)

More information on all the changes in Xamarin Studio 5.10 can be found in the release notes.

NuGet 2.8.7 support

Xamarin Studio now supports NuGet 2.8.7. NuGet 2.8.7 adds support for the Universal App Platform (UAP) target framework to support Windows 10 Application Development.

Open readme.txt when a NuGet package is installed

A NuGet package can contain a readme.txt file which Xamarin Studio will now open and display in the text editor when the NuGet package is installed or updated.

Preserve Local Copy on Updating Packages

The Local Copy setting on an assembly reference will now be preserved when updating a NuGet package or retargeting a NuGet package.

By default Local Copy is set to true for assembly references when installing a NuGet package. If you set Local Copy to false for one or more of these references then this setting will now be preserved when updating or retargeting the NuGet package.

Packages.config file named after project

NuGet supports multiple projects in the same directory each using their own packages.config file. To allow multiple projects in the same directory to each use their own NuGet packages you can name the packages.config file after each project. In the examples below the project filename is on the left and the corresponding packages.config filename is on the right.

  • Foo.csproj => packages.Foo.config
  • Bar.csproj => packages.Bar.config
  • Foo Bar.csproj => packages.Foo_Bar.config

Xamarin Studio now checks for the packages.ProjectName.config file first and will use it if it exists, otherwise it will fall back to the default behaviour and use the packages.config file.

Note that a new project without any NuGet packages will use a packages.config file by default. The basic procedure to enable a project specific packages.config file when creating a new project is:

  1. Create new project called Foo.
  2. Add a NuGet package to the Foo project.
  3. Rename the packages.config file to packages.Foo.config
  4. Reload the solution in Xamarin Studio.

Also note that if you remove all the NuGet packages from a project the packages.ProjectName.config file will be deleted and on adding a new NuGet package the default packages.config file will be used.

Do not show Checking for package updates message in status bar

Previously when Xamarin Studio was checking for NuGet package updates a message would appear in the status bar. This status bar message has now been removed since checking for NuGet package updates is a background task and does not prevent Xamarin Studio from being used.

Do not show warning in the status bar if a NuGet package has PowerShell scripts

Previously if a NuGet package was installed and it contained PowerShell scripts then a warning was shown in the status bar. Now this message is only shown in the Package Console window.

Prevent the solution being closed when NuGet packages are being added

A check is now made when Xamarin Studio is closed to see if NuGet packages are still being installed. If this is the case then a dialog will be displayed indicating that it is not currently possible to close Xamarin Studio allowing the NuGet package to finish installing.

Support NuGet packages targeting watchOS

A new Xamarin.WatchOS target framework is now supported which allows NuGet packages to contain assemblies for watchOS.

Package license acceptance

Xamarin Studio 5.10.3 now includes a license acceptance dialog that will be displayed if a NuGet package requires a license to be accepted before it is installed. If the license is declined then the NuGet package will not be installed.

Package license acceptance dialog

Bug Fixes

Removing a NuGet package does not update the Solution window when multiple solutions are open

With two or more solutions opened at the same time the Packages folder would not be updated for all solutions when a NuGet package was removed. This was because Xamarin Studio was not refreshing the Packages folder for all solutions currently open.

Prevent packages.config file being marked as deleted by Git after updating pre-release NuGet package.

If there was only one pre-release NuGet package installed into a project and then a later version of the NuGet package was installed from the Add Packages dialog then the packages.config file was then being shown as deleted by Git instead of modified.

The packages.config file is deleted by NuGet after the old NuGet package is uninstalled if there are no NuGet packages referenced. A special case to handle this was added in Xamarin Studio 5.3 but that only handled updating a NuGet package from the Solution window. Now updating a pre-release from the Add Packages dialog is also handled.

Retargeting a NuGet package marks packages.config as deleted by Git

This is similar to the previous bug. Retargeting a NuGet package will uninstall and then install the NuGet package. If there is only one NuGet package in the project then the packages.config file is deleted and was causing Git to mark the file as deleted instead of updated.

Unable to install Microsoft.ApplicationInsights NuGet package

Xamarin Studio 5.9.2 added support for NuGet 2.8.5 but it was not possible to install the Microsoft.ApplicationInsights NuGet package into a project. It was possible to install it using Visual Studio with NuGet 2.8.3 or higher installed. The error reported by Xamarin Studio was:

Adding Microsoft.ApplicationInsights...
The 'Microsoft.ApplicationInsights' package requires NuGet client version '2.8.50313' or above, but the current NuGet version is '2.8.5.0'.

Xamarin Studio 5.10 now allows the Microsoft.ApplicationInsights NuGet package to be installed into a project.

TypeScript Addin 0.6 Released

A new version of the TypeScript addin for Xamarin Studio and MonoDevelop has been released. The addin is available from MonoDevelop’s Add-in Repository in the alpha channel. More details on how to install the addin can be found in the TypeScript support in Xamarin Studio post.

Changes

  • Updated to support TypeScript 1.5.
  • Linux 32 bit and 64 bit are now supported with a single addin. Thanks to Christian Bernasko.
  • Allow UMD and System modules to be selected in project options.

The separate TypeScript Linux 32 bit addin is now deprecated since the TypeScript addin can now be used on 32 bit and 64 bit versions of Linux.

Bug Fixes

  • TypeScript language service host not updated when the project options are changed

For example, switching from ES3 to ES6 in the project options could cause the code completion to be incorrect since the language service host compiler settings were not being updated.

  • TypeScript options shown when viewing solution options

The TypeScript options are now only available when the project options are selected.

Paket Support in Xamarin Studio

Xamarin Studio and MonoDevelop now have support for Paket with an alpha release of the Paket Addin.

Paket is a dependency manager for .NET. The dependencies it supports are NuGet packages, files from GitHub, Gists or files from any HTTP source. Paket can be used to maintain project dependencies completely from the command line.

So let us take a look at the support for Paket in Xamarin Studio and MonoDevelop.

Features

  • View dependencies and referenced NuGet packages in the Solution window.
  • Add, remove, update NuGet packages from the Solution window.
  • Install, restore, simplify NuGet packages from the Solution window.
  • Check for updated NuGet packages from the Solution window.
  • Syntax highlighting for all paket files.
  • Code completion whilst editing the paket.dependencies file.
  • Integrates with Xamarin Studio’s unified search.
  • paket.dependencies and paket.template file templates.

Installing the addin

The addin is currently available from MonoDevelop’s Add-in Repository in the alpha channel. In Xamarin Studio open the Add-in Manager and select the Gallery tab. Click the repository drop down and if Xamarin Studio Add-in Repository (Alpha Channel) is not displayed then click Manage Repositories…. In the window that opens tick the check box next to Xamarin Studio Add-in Repository (Alpha Channel) and then click the Close button.

Enabling alpha channel addins

Back in the Add-in Manager dialog click the Refresh button to update the list of addins. Use the search text box in the top right hand corner of the dialog to search for the addin by typing in Paket.

Paket addin selected in Addin Manager dialog

Select the Paket addin and then click the Install… button.

Now let us take a look at adding a NuGet package to your project with Paket. This is a simple way to get started with Paket in Xamarin Studio without having to manually create any paket files.

Adding a NuGet Package

To add a NuGet package using Paket, right click the project in the Solution window, and select Add – Add NuGet Packages using Paket.

Add NuGet Package using Paket Solution window context menu

The Add NuGet Packages using Paket menu is also available from the main Project menu.

This opens the Add NuGet Packages dialog. Search for the NuGet package you want to use and click the Add Package button.

Add NuGet Packages dialog

The Status Bar will update as the NuGet package is installed.

Json.NET added status bar message

More detailed information about the installation can be found in the Paket Console window. This can be opened by clicking the Status Bar or from the View – Pads menu.

Json.NET added Paket Console messages

After the NuGet package has been installed successfully you will see two new items in the Solution window. A Paket Dependencies folder and a Paket References folder.

Paket folders in Solution window

These folders show the NuGet packages that are in the paket.dependencies and paket.references files.

Paket Dependencies Folder

The Paket Dependencies folder is shown in the Solution window if Xamarin Studio finds a paket.dependencies file in the same directory as the solution. The NuGet packages that are in the paket.dependencies file are shown under this folder.

Paket Dependencies folder in Solution window

Double clicking the folder will open the paket.dependencies file into the text editor. The Paket Dependencies folder also has a context menu where you can run Paket commands.

Paket Dependencies folder context menu

From the context menu you can Add a NuGet Package as a dependency, install, restore, update, and simplify your dependencies, or check for updates. When you select Check for Updates the updated NuGet package information will be shown in the Paket Console and in the Solution window.

Paket Dependencies folder NuGet package update information

To update a single NuGet package you can right click it and select Update. To remove the NuGet package as a dependency you can right click it and select Remove or press delete.

Paket Dependencies folder NuGet package context menu

Paket References Folder

The Paket References folder is shown in the Solution window if Xamarin Studio finds a paket.references file in the same directory as the project. The NuGet packages that are in the paket.references file are shown under this folder. Double clicking the folder will open the paket.references file into the text editor.

Paket References folder in Solution window

Right clicking the Paket References folder allows you to add a NuGet package to the project.

Paket References folder context menu

A NuGet package can be removed by right clicking it and selecting Remove or by pressing Delete.

Paket References folder NuGet package context menu

Code Completion

When editing the paket.dependencies file you will get code completion as you type. You can also bring up the code completion list by pressing Ctrl+Space.

paket.dependencies file keyword completion

Keywords that have an associated value will also show code completion after a space is pressed or the first character is typed in.

paket.dependencies file keyword value completion

After the source keyword you will see a list of NuGet package sources that are defined in your NuGet.Config file.

paket.dependencies file NuGet source completion

After the nuget keyword you will see a list of NuGet packages.

paket.dependencies file NuGet package completion

This list of NuGet packages is currently taken from your local machine’s NuGet cache. Currently there is no support for asynchronously searching an online NuGet package source to get the list of NuGet packages.

Running Paket commands

Paket commands can be run from the Unified search. If you type in paket you will see some of the Paket commands.

Paket commands in unified search

The syntax for each command is the similar to what the paket.exe console application supports but the commands do not support all the parameters.

As you type more of the command the list of commands will be filtered. To run a command select it and then press the enter key. These commands directly run paket.exe and update the paket files and project files. The status of the current command is shown in the Status Bar and the output from paket.exe is shown in the Paket Console window.

Paket dependencies installed status bar message

Paket dependencies installed console message

The Paket Console window will automatically be displayed if there was an error running a command and an error message will be displayed in the Status Bar.

Paket error message in Status Bar

Paket console error message

Otherwise you can open the Paket Console by clicking the Status Bar.

Syntax highlighting

Syntax highlighting is available for all paket files – paket.dependencies, paket.references, paket.lock and paket.template.

paket.dependencies file syntax highlighting

paket.lock file syntax highlighting

This brings us to the end of the introduction to Paket support in Xamarin Studio.

NuGet Support in Xamarin Studio 5.9.2

Changes

  • NuGet 2.8.5 support
  • NuGet warning and error messages in Status Bar

More information on all the changes in Xamarin Studio 5.9.2 can be found in the release notes.

NuGet 2.8.5 support

Xamarin Studio now supports NuGet 2.8.5.

NuGet 2.8.5 adds support for three new .NET target frameworks: DNX, DNXCore and Core.

With NuGet 2.8.5 supported you can now install the latest pre-release version of xUnit.

NuGet warning and error messages in Status Bar.

Xamarin Studio 5.9 has a new native Status Bar on the Mac. This new Status Bar has a smaller width so the NuGet warning and error messages could be too long to be displayed. The screenshots below show a NuGet warning and error message in Xamarin Studio 5.9 that do not fit in the Status Bar.

NuGet warning message truncated in status bar

NuGet error message truncated in status bar

In Xamarin Studio 5.9.2 the NuGet Status Bar messages have been shortened so they can be displayed in the new Status Bar without being truncated. The screenshots below show the new format of the NuGet warning and error messages shown in the Status Bar.

Shortened NuGet warning message in status bar

Shortened NuGet error message in status bar

Xamarin Components Directory Configuration

One of the new features introduced in Xamarin Studio 5.9 is the ability to configure the directory where Xamarin Components are installed to when they are added to a project.

By default, when a Component from the Xamarin Component store is added to a project, the Component is installed to a Components directory inside the solution’s directory.

Default Components directory for a solution

The project will have references added that refer to assemblies inside this Components directory.

<Reference Include="Microsoft.WindowsAzure.Mobile.Ext">
  <HintPath>..\Components\azure-mobile-services-1.3.1\lib\android\Microsoft.WindowsAzure.Mobile.Ext.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Mobile">
  <HintPath>..\Components\azure-mobile-services-1.3.1\lib\android\Microsoft.WindowsAzure.Mobile.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
  <HintPath>..\Components\azure-mobile-services-1.3.1\lib\android\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Extensions">
  <HintPath>..\Components\azure-mobile-services-1.3.1\lib\android\System.Net.Http.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Primitives">
  <HintPath>..\Components\azure-mobile-services-1.3.1\lib\android\System.Net.Http.Primitives.dll</HintPath>
</Reference>

If a project is shared between multiple solutions then Xamarin Studio can have multiple different Components directories, one for each solution. This can cause Xamarin Studio to modify the hint paths in the project file to use a different Components directory depending on which solution was opened.

A simple way to reproduce this problem is to create one solution with a project that has a Component, then create another solution in a different directory, and add the same project to this new solution. The Component will be downloaded again into the Components directory relative to the new solution and the assembly references in the project file will be modified to use this new Components location.

Now let us take a look at how to solve this problem by configuring the Components directory.

Configuring the Components Directory

To configure the Components directory used by a project you can use a components.config file, as shown below.

<components>
  <config>
    <add key="cachePath" value="..\Components" />
  </config>
</components>

The path specified in the components.config file can be a full path or a relative path. If it is a relative path then it is relative to the directory containing the components.config file.

The path in the components.config file will be normalized so it contains the correct directory separators on non-Windows operating systems, so you can use either a forward slash or a backslash in the path.

Now let us take a look at how Xamarin Studio finds this components.config file.

Xamarin Studio, when a solution is opened, will check for a components.config file in several locations based on the solution’s directory. If we have a solution in the directory /Users/matt/Projects/MyAndroidApp/ then the full set of locations checked is as follows:

  1. /Users/matt/Projects/MyAndroidApp/.components/components.config
  2. /Users/matt/Projects/MyAndroidApp/components.config
  3. /Users/matt/Projects/components.config
  4. /Users/matt/components.config
  5. /Users/components.config
  6. /components.config
  7. ~/Library/Preferences/Xamarin/Components/components.config

Note that on Windows the last location checked is:

%AppData%\Xamarin\Components\components.config

If you put the components.config file in a directory that is a parent of multiple solutions then all the solutions can use this common components.config file.

If the components.config file is missing or cannot be read then the default Components directory is used, which is inside the solution’s directory.

If there is an error whilst reading the components.config file then the error will be logged by Xamarin Studio and the default Components directory will be used.

The Components directory to be used is cached when the solution is loaded so changes made to the components.config file require the solution to be closed and re-opened before Xamarin Studio will use the new settings.

To help diagnose problems when configuring the Components directory Xamarin Studio will log information in the Components.log file. The Components.log file can be found by selecting Open Log Directory from Xamarin Studio’s Help menu. Two examples taken from the Components.log file are shown below. The first example shows the message logged when a components.config file cannot be found.

[2015-05-10 11:00:29.0] DEBUG: No components.config file found. Using default path. Files checked: /Users/matt/Projects/MyAndroidApp/.components/components.config
/Users/matt/Projects/MyAndroidApp/components.config
/Users/matt/Projects/components.config
/Users/matt/components.config
/Users/components.config
/components.config
/Users/matt/Library/Preferences/Xamarin/Components/components.config

The next example shows the message logged when a components.config file is found.

[2015-05-10 11:10:24.1] DEBUG: Using custom components cache path '/Users/matt/Projects/MyAndroidApp/Components'. components.config file found at '/Users/matt/Projects/MyAndroidApp/components.config'.

Component Restore

The latest version of xamarin-component.exe also supports using the configured Components directory. Its restore command will restore the Components to the directory as specified in the components.config file.

mono xamarin-component.exe restore path/to/solution.sln

xamarin-component.exe will look for the components.config file in the same directories as Xamarin Studio.

Comparison with NuGet

NuGet has similar behaviour to Components in Xamarin Studio. All NuGet packages are downloaded to a packages directory inside the solution directory by default. To override this behaviour you can create a NuGet.Config file. The NuGet.Config file allows the packages directory to be configured through a repositoryPath setting.

<configuration>
  <config>
    <add key="repositoryPath" value="../../packages" />
  </config>
</configuration>

NuGet will look for this NuGet.Config file in several places. Assuming the solution directory is /Users/matt/Projects/MyAndroidApp/ the NuGet.Config file will be looked for in the locations as shown below:

  1. /Users/matt/Projects/MyAndroidApp/.nuget/NuGet.Config
  2. /Users/matt/Projects/MyAndroidApp/NuGet.Config
  3. /Users/matt/Projects/NuGet.Config
  4. /Users/matt/NuGet.Config
  5. /Users/NuGet.Config
  6. /NuGet.config
  7. ~/.config/NuGet/NuGet.Config (Windows: %AppData%\NuGet\NuGet.Config)

NuGet Support in Xamarin Studio 5.9

Changes

  • NuGet 2.8.3 support
  • Always show Packages folder in Solution window
  • Target framework change detected on project reload

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

NuGet 2.8.3 support

Xamarin Studio now supports NuGet 2.8.3. This allows a NuGet package to target NuGet 2.8.3 explicitly. For example the PCLStorage 1.0.1 NuGet package will not install into Xamarin Studio 5.8, since it requires NuGet 2.8.3, but will install into Xamarin Studio 5.9.

NuGet packages, such as xunit, that target the new ASP.NET target frameworks, ASP.NetCore 5.0 and ASP.Net 5.0, can now be installed into Xamarin Studio now that it supports NuGet 2.8.3. Previously you would see an error message in the Package Console window:

'xunit.core' already has a dependency defined for 'xunit.extensibility.core'.

Support for NuGet 2.8.5 is planned for Xamarin Studio 5.9.1.

Always Show Packages Folder in Solution window

The Packages folder is now always shown in the Solution window even if the project has no NuGet packages. Previously the Packages folder would only be shown if one or more NuGet packages were installed in a project.

Packages folder in Solution window

Target Framework Change Detected on Project Reload

Xamarin Studio will detect a project file has been changed outside of Xamarin Studio and will reload the project. Now Xamarin Studio on reloading will detect the project’s target framework has been changed and will check the NuGet packages are compatible with the new target framework. Previously Xamarin Studio would only check the compatibility of NuGet packages if the target framework was changed from within Xamarin Studio via the project options.

This allows Xamarin Studio to check the NuGet packages are compatible when an iOS Classic project is converted to an iOS Unified project using Xamarin Studio’s migration tool. The NuGet packages, such as Xamarin.Forms, can then be retargeted by Xamarin Studio using the Retarget menu.

TypeScript Support in Xamarin Studio

Xamarin Studio and MonoDevelop now have support for TypeScript on Linux, Mac and Windows with an alpha release of the TypeScript Addin.

Editing TypeScript in Xamarin Studio on the Mac

The TypeScript addin uses V8.NET which is a library that allows a .NET application to host Google’s V8 JavaScript engine and have JavaScript interact with .NET objects in the host application.

The ability to support Windows, Mac and Linux would not have been possible without the work done by James Wilkins and Christian Bernasko. James Wilkins created the V8.NET library and when it was first released it supported only Windows. Christian Bernasko then took V8.NET and modified it to make it work with Mono on Linux and the Mac. The TypeScript addin is using V8.NET binaries built by Christian from his port of V8.NET.

Please note that this is an alpha release and because V8.NET uses a native library it can cause Xamarin Studio or MonoDevelop to terminate if a bug is encountered.

Features

  • TypeScript compilation on save or build.
  • Code completion.
  • Find references.
  • Rename refactoring.
  • Go to declaration.
  • Errors highlighted as you type.
  • Code folding.

The addin supports:

  • Xamarin Studio MonoDevelop 5 and above.
  • TypeScript 1.4
  • Linux, Mac and Windows.

Installing the addin

The addin is currently available from MonoDevelop’s Add-in Repository in the alpha channel. By default the alpha repository is not enabled so you will have to enable it before you can find and install the addin.

In Xamarin Studio open the Add-in Manager and select the Gallery tab. Click the repository drop down and if Xamarin Studio Add-in Repository (Alpha Channel) is not displayed then click Manage Repositories…. In the window that opens tick the check box next to Xamarin Studio Add-in Repository (Alpha Channel) and then click the Close button.

Enabling alpha channel addins

Back in the Add-in Manager dialog click the Refresh button to update the list of addins. Use the search text box in the top right hand corner of the dialog to search for the addin by typing in TypeScript.

TypeScript addin selected in Addin Manager dialog

Select the TypeScript addin and then click the Install… button.

Note that if you are using Linux 32 bit then you should install the TypeScript Linux 32 bit addin. The other TypeScript addin listed supports Linux 64 bit. Hopefully in the future it will be possible to support both Linux 32 bit and 64 bit using the same addin.

Getting Started

Now that the TypeScript addin is installed let us create a TypeScript file.

To add a TypeScript file open the New File dialog, select the Web category and select Empty TypeScript file.

New File Dialog - New TypeScript File

Give the file a name and click the New button.

Note that currently the TypeScript file needs to be included in a project. Standalone TypeScript project files are not supported. TypeScript files can be added to any .NET project.

Code Completion

When editing the TypeScript code you will have code completion when you press the dot character.

TypeScript dot code completion

Code completion also works when you type the opening bracket of a function.

TypeScript method completion

Go to Declaration

The text editor’s right click menu has three TypeScript menus: Go to Declaration, Find References and Rename.

Text editor context menu with TypeScript menu options

The Go To Declaration menu option will open the corresponding definition in the text editor.

Find References

Find References will show the references in the Search Results window.

TypeScript references shown in Search Results window

Rename

Selecting the Rename menu option in the text editor will open the Rename dialog where you can type in a new name and click OK to have it updated.

TypeScript rename dialog

Note that currently on Linux the Rename dialog will only be displayed if the keyboard shortcut F2 is used. Selecting the context menu will not show the Rename dialog on Linux but will work on Windows and on the Mac.

Error Highlighting

Errors in your TypeScript code will be highlighted as you are typing in the text editor.

TypeScript errors highlighted in text editor

Code Folding

Code folding is supported for TypeScript classes, modules and interfaces.

TypeScript code folding

Code folding by default is disabled. To enable code folding open the Preferences dialog and in the Text Editor section select the General category, then tick the Enable code folding check box.

Preferences - Enabling code folding

Compiling to JavaScript

By default the TypeScript files will be compiled to JavaScript when the project is compiled.

There are more compiler options available in the project options in the Build – TypeScript category.

TypeScript compiler options for the project

On this page you can change when the compiler is run and what options are passed to the compiler when generating JavaScript code.

If an Output file is specified then all the TypeScript files will be compiled into a single JavaScript file. If an Output directory is specified then the JavaScript files will be generated in that directory instead of next to the TypeScript files.

That is the end of our quick look at TypeScript support in Xamarin Studio and MonoDevelop.

Source Code

The source code for the addin and for the V8.NET engine that works on Mono are available on GitHub.