Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Set up a Xamarin Forms project to use the MSAL .NET SDK

Jim Crowley edited this page Dec 6, 2016 · 8 revisions

If you create a Visual Studio Xamarin Forms solution with the existing Xamarin Forms template, you get this error message when you try to install the Microsoft Authentication Library (MSAL) into the solution's Portable Class Library (PCL) via Nuget:

Could not install package 'Microsoft.Identity.Client 1.0.304142221-alpha'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not contain any assembly references or content files that are compatible with that framework.

Since MSAL does not target the .NETPortable framework, you'll need to remove the Windows Phone 8.1 build target from the Xamarin Forms and Windows Phone 8.1 project from your Xamarin Forms solution.

Removing the Windows Phone project is easy. Simply locate the Windows Phone 8.1 project in your solution. Right-click the project name, and select Remove from the menu.

##Remove the Windows Phone 8.1 build target

Removing the Windows Phone 8.1 build target requires a few extra steps, because removing this target will require the Portable Class Library project to opt into NuGet 3.0 support. In order to upgrade to NuGet 3.0 from the Xamarin Forms PCL, you'll need to remove all NuGet packages (in this case, just the Xamarin.Forms package), remove the Windows Phone 8.1 build target, and then add all of the NuGet packages that you need, including and especially Xamarin.Forms and MSAL. In order to do that, follow these steps:

  1. Right-click the PCL project name, and select Manage NuGet Packages.

  2. In the NuGet Package Manager page, select the Installed tab, and you'll see the Xamarin.Forms package. Note the version number that you're using so that you'll know which version to choose when you re-install the package (unless you want to upgrade to the latest stable version).

  3. Select the Uninstall button to remove the Xamarin.Forms package.

  4. Right-click the PCL project (at the top of the Solution Explorer), and select Properties.

  5. From the Library tab of the Project properties page, select the Change button at the bottom of the Targeting section.

  6. In the Change Targets window, uncheck the Windows Phone 8.1 and Windows Phone Silverlight 8.1 targets. Select OK.

  7. Return to the NuGet Package Manager page. Select the Browse tab. Use the search box at the top to find and reinstall the Xamarin.Forms package.

  8. Select the Include pre-release box next to the search box and search for Microsoft.Identity. This is the MSAL package. Install the latest version of the package.

Now you can get started writing code that uses MSAL to authenticate users with either work or school or consumer Microsoft accounts. Be sure to add MSAL to all of the projects in your Xamarin Forms solution, not just the PCL.

Clone this wiki locally