Xamarin.Forms And The Case of Failed NuGet Packages – Part 2

Most enterprise mobile apps require enterprise-level authentication mechanism. In that case, people use tried and tested Active Directory Authentication Library (ADAL) or Microsoft Authentication Library (MSAL). ADAL is in GA and it works fine with cross-platform mobile apps built using Xamarin. However, MSAL is in ‘preview’ and it offers nightly builds to try out. I wanted to try the latest nightly build (ver: 1.1.1-alpha0417) as it uses updated Android Support Package and old preview bits of MSAL (ver: 1.1.0-preview) were not compatible with latest  Xamarin.Forms anymore. Here, I was trying to build one app over holidays and I got stuck on one interesting issue. Let’s discuss it in this blog post.

The Problem:

When you create a blank Xamarin.Forms app, it automatically references Xamarin.Forms NuGet along with all the required dependencies.

At this time, when you’ll try to install MSAL, you may get stuck at this issue of versioning.

The reason being Xamarin.Forms NuGet requires a specific version of Android Support Packages whereas Microsoft Authentication Library requires anything above Ver. 25.3.1.

The Solution:

Sometimes, things are very simpler than it looks. I spent a lot of time on solving this issue but was unable to fix it. Thanks to my friend Nish, who helped me with his ‘ problem-solving skills’ and we got this working.

The solution is simple:

  1. Remove all NuGet packages from Android project. For the sake of it, close and restart Visual Studio.
  2. Open the solution and Install MSAL NuGet package first.
  3. After installing MSAL NuGet, install Xamarin.Forms NuGet package.

Bingo!

Now you can build Xamarin.Forms apps with Microsoft Authentication Library. If you want to know more about how to use the SDK, follow the blog post here on Xamarin blog.

Even though I’m talking about Xamarin.Forms and MSAL here, this blog post is very much applicable wherever you’re trying to use any NuGet package which has updated dependency on Android Support Package.

Setup info:
Visual Studio Enterprise 2017 Preview (15.5.2)
Xamarin (4.8.0.753)
Xamarin.Forms (2.5.0.121934)
Microsoft Authentication Library (1.1.1-alpha0417)

Namaste,
Mayur Tendulkar

 

Learn Mobile App Dev & Mobile DevOps Here

DevOps Meme

My friend Prachi tagged me on this meme on Facebook and I couldn’t agree more with her. When I started my career, my entire version control was folders – zipped, tagged and stored on multiple hard-disks. But then things changed. My guru Raj, enlightened me about advantages of version control systems. I learned about how multiple people can collaborate on projects or how errors can be reversed by going through code history if version controls like Team Foundation Server or GitHub are used. I started using those and these days, all my projects and samples are either in Visual Studio Team Services or in GitHub repository.  Going one step ahead, I’m using Visual Studio Mobile Center for DevOps along with these version control systems.

But what is this all about? How it helps in building successful mobile applications? And I thought about answering these questions in a video series. The goal is to explain mobile DevOps and different steps in mobile DevOps in small (less than 10 mins) videos.  After completing this series, you’ll be able to build cross-platform Xamarin.Forms mobile application, which will consume Microsoft Cognitive Service and set-up mobile DevOps for the same.

To follow along with this series, I’m recommending following minimum hardware/software combination:

  • Intel i5, 8GB, 50GB machine with Hyper-V support & Windows 10 Professional
  • MacBook or MacMini with i5, 4GB, 50GB for compiling iOS apps
  • Visual Studio 2017 Community Preview

With these hardware/software additional services used in this series are:

Watch the 1st video here about activating these tools & services to set-up mobile DevOps.

In 2nd video learn about how to setup build automation, using Visual Studio Mobile Center.

I’ll update this blog post in coming weeks with the 3rd video in this series, which will be about building mobile applications.

Stay tuned and subscribe to my blog/channel :)

Namaste.
Mayur Tendulkar

Xamarin.Forms And The Case of Failed NuGet Packages

When you create a Xamarin.Forms project, chances are there will be updates available for Xamarin.Forms libraries and associated packages. You can check for updates to NuGet packages manually or these will be restored before “build”.

The Problem:

When you create a new Xamarin.Forms app or open existing one, if you’ve fresh formatted machine with fresh VS and Xamarin installation, the build may last for longer than expected. The reason for this being, it downloads NuGet packages along with its dependencies like Android Support Packages. If in between, VS hangs or there are interruptions in network, you’ll see some errors in build like this:

XF-NUGET-02

The solution:

Well, at first you may think it is issue with Xamarin or Visual Studio or NuGet. But this all has to do with lot of NuGet packages and their dependencies download. So it all depends on machine config and network connectivity. If ever you see above errors follow the below steps:

1) Start from fresh. Close Visual Studio instances and delete everything under %appdata%local/Xamarin (e.g. C:\Users\mayur\AppData\Local\Xamarin)

2) Launch Visual Studio and open the solution. Right click each project and update NuGet packages. Android is the one which will take longer to update.

XF-NUGET-03

3) Wait till all packages are downloaded. Make sure the %appdata% folder contents all the necessary directories and files.

XF-NUGET-04

4) Build the solution. And if you still get issues about some missing some resources. Open Android SDK Manager from Tools > Android and make sure right API levels (in this case API Level 23) is installed.

XF-NUGET-05

Now run the project and it should run without any issues.

XF-NUEGT-06

Namaste,
Mayur Tendulkar