Avoid Nightmares Updating the .Net Backend Project From Azure Mobile Services

Scope

The purpose of this article is to show how to update a .Net Backend project from Azure Mobile Services. This mean we will update the references added to the project using Nuget packages.

Introduction

Microsoft Azure Mobile Services is an Azure service offering designed to make it easy to create highly-functional mobile apps using Azure. Mobile Services brings together a set of Azure services that enable backend capabilities for your apps.

When a developer creates a .Net Backend project from Azure Mobile Services, it has several Nuget packages installed. For example, if the project is created in Visual Studio 2013 Update 4, like we can see in the Image 1.

Azure Mobile Service
                              Image 1 Creating the Azure Mobile Service

The default package files will be something such as the following:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <packages>  
  3.   <package id="Autofac" version="3.5.2" targetFramework="net45" />  
  4.   <package id="AutoMapper" version="3.2.1" targetFramework="net45" />  
  5.   <package id="EntityFramework" version="6.1.1" targetFramework="net45" />  
  6.   <package id="Microsoft.AspNet.Cors" version="5.2.2" targetFramework="net45" />  
  7.   <package id="Microsoft.AspNet.Identity.Core" version="2.0.1" targetFramework="net45" />  
  8.   <package id="Microsoft.AspNet.Identity.Owin" version="2.0.1" targetFramework="net45" />  
  9.   <package id="Microsoft.AspNet.Razor" version="3.2.2" targetFramework="net45" />  
  10.   <package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" />  
  11.   <package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net45" />  
  12.   <package id="Microsoft.AspNet.WebApi.Cors" version="5.2.2" targetFramework="net45" />  
  13.   <package id="Microsoft.AspNet.WebApi.OData" version="5.2.2" targetFramework="net45" />  
  14.   <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.2" targetFramework="net45" />  
  15.   <package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.2" targetFramework="net45" />  
  16.   <package id="Microsoft.Data.Edm" version="5.6.2" targetFramework="net45" />  
  17.   <package id="Microsoft.Data.OData" version="5.6.2" targetFramework="net45" />  
  18.   <package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" />  
  19.   <package id="Microsoft.Owin.Host.SystemWeb" version="2.1.0" targetFramework="net45" />  
  20.   <package id="Microsoft.Owin.Security" version="2.1.0" targetFramework="net45" />  
  21.   <package id="Microsoft.Owin.Security.ActiveDirectory" version="2.1.0" targetFramework="net45" />  
  22.   <package id="Microsoft.Owin.Security.Cookies" version="2.1.0" targetFramework="net45" />  
  23.   <package id="Microsoft.Owin.Security.Facebook" version="2.1.0" targetFramework="net45" />  
  24.   <package id="Microsoft.Owin.Security.Google" version="2.1.0" targetFramework="net45" />  
  25.   <package id="Microsoft.Owin.Security.Jwt" version="2.1.0" targetFramework="net45" />  
  26.   <package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.1.0" targetFramework="net45" />  
  27.   <package id="Microsoft.Owin.Security.OAuth" version="2.1.0" targetFramework="net45" />  
  28.   <package id="Microsoft.Owin.Security.Twitter" version="2.1.0" targetFramework="net45" />  
  29.   <package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net45" />  
  30.   <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />  
  31.   <package id="Owin" version="1.0" targetFramework="net45" />  
  32.   <package id="RazorEngine" version="3.4.1" targetFramework="net45" />  
  33.   <package id="System.IdentityModel.Tokens.Jwt" version="3.0.2" targetFramework="net45" />  
  34.   <package id="System.Spatial" version="5.6.2" targetFramework="net45" />  
  35.   <package id="WindowsAzure.MobileServices.Backend" version="1.0.405" targetFramework="net45" />  
  36.   <package id="WindowsAzure.MobileServices.Backend.Entity" version="1.0.405" targetFramework="net45" />  
  37.   <package id="WindowsAzure.MobileServices.Backend.Tables" version="1.0.405" targetFramework="net45" />  
  38.   <package id="WindowsAzure.ServiceBus" version="2.3.4.0" targetFramework="net45" />  
  39. </packages> 

But if we “Manage Nuget Packages” and select “Updates”, the windows will show that there are updates that we can do, like we can see in the Image 2.

Manage Nuget Packages
                                 Image 2 Manage Nuget Packages - Available Updates

The first thing we can try to do is to click the “Update All” button, that will make sense for developers, but then we will get something as we can see in Image 3.

Error updating all
                                    Image 3 Error updating all

And here are the nightmares about updating the Nuget packages from Azure Mobile Services. Start, because like we can see in the package file, we have 36 Nuget packages installed in the project and it is not so easy to understand the dependencies among the various Nuget packages and if we start updating them one by one we will get errors as in the following in Image 4. So with this it is not possible to update one by one, but the main Nuget packages and in this article we will see how to avoid this problem.

Azure Mobile Service with errors
                                          Image 4 Azure Mobile Service with errors

In other words the reference added to the project is not the same version used by any Nuget and it can be hard to understand which is the right version.

Description


To understand the Nuget packages and because our project is an Azure Mobile Service project, we can start by analyzing the packages.

  1. <package id="WindowsAzure.MobileServices.Backend" version="1.0.405" targetFramework="net45" />  
  2. <package id="WindowsAzure.MobileServices.Backend.Entity" version="1.0.405" targetFramework="net45" />  
  3. <package id="WindowsAzure.MobileServices.Backend.Tables" version="1.0.405" targetFramework="net45" /> 

In the Nuget website we found

  • Microsoft Azure Mobile Services .NET Backend 1.0.405

    Has the dependencies:
    • Newtonsoft.Json (≥ 6.0.4)
    • Microsoft.Owin (≥ 3.0.0)
    • Autofac (≥ 3.5.2)
    • Microsoft.AspNet.Identity.Owin (≥ 2.0.1)
    • Microsoft.AspNet.WebApi.Cors (≥ 5.2.2)
    • Microsoft.AspNet.WebApi.Owin (≥ 5.2.2)
    • Microsoft.AspNet.WebApi.Tracing (≥ 5.2.2)
    • Microsoft.Owin.Security.ActiveDirectory (≥ 2.1.0)
    • Microsoft.Owin.Security.Facebook (≥ 2.1.0)
    • Microsoft.Owin.Security.Google (≥ 2.1.0)
    • Microsoft.Owin.Security.MicrosoftAccount (≥ 2.1.0)
    • Microsoft.Owin.Security.Twitter (≥ 2.1.0)
    • RazorEngine (≥ 3.4.1)
    • WindowsAzure.ServiceBus (≥ 2.3.4.0)

  • Microsoft Azure Mobile Services .NET Backend Tables 1.0.405

    Has the dependencies:

    • WindowsAzure.MobileServices.Backend (≥ 1.0.405)
    • Microsoft.Data.OData (≥ 5.6.2)
    • Autofac (≥ 3.5.2)
    • Microsoft.AspNet.WebApi.OData (≥ 5.2.2)
    • Microsoft.AspNet.WebApi.Tracing (≥ 5.2.2)
    • Microsoft.Owin.Security.OAuth (≥ 2.1.0)

  • Microsoft Azure Mobile Services .NET Backend Entity Framework Extension 1.0.405.

    Has the dependencies.

    • WindowsAzure.MobileServices.Backend.Tables (≥ 1.0.405)
    • Autofac (≥ 3.5.2)
    • AutoMapper (≥ 3.2.1)
    • EntityFramework (≥ 6.1.1)
    • Microsoft.AspNet.WebApi.OData (≥ 5.2.2)
    • Microsoft.AspNet.WebApi.Tracing (≥ 5.2.2)
    • Microsoft.Owin.Security.OAuth (≥ 2.1.0)

This way, we can conclude the Microsoft Azure Mobile Services .NET Backend Entity Framework Extension 1.0.405 Nuget depends on the WindowsAzure.MobileServices.Backend.Tables Nuget and this depends on the WindowsAzure.MobileServices.Backend Nuget. This means if we update the Microsoft Azure Mobile Services .NET Backend Entity Framework Extension Nuget the references related to Azure Mobile Services will be updated.

In the “Manage Nuget Package” click in update the Microsoft Azure Mobile Services .NET Backend Entity Framework Extension Nuget, as we can see in Image 5:

Updating Nuget
                                                         Image 5 Updating Nuget

And then, click “I Accept”.

License
                           Image 6 License

At the end, we will get:

Nuget packages updated
                                             Image 7 Nuget packages updated

With this another question can be raised, “Did we update all Nuget packages we can?” and this question can be answered by uninstalling the Microsoft Azure Mobile Services .NET Backend Entity Framework Extension Nuget, as in the Image 8:

Uninstall Nuget
                                                      Image 8 Uninstall Nuget

Uninstalling this Nuget will request a confirmation to uninstall all the dependencies, as in the Image 9, where we will click in “Yes”.

Nuget packages to remove
                               Image 9 Nuget packages to remove

The result will be:

the service running in localhost
                                          Image 10 the service running in localhost

And the package file updated to:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <packages>  
  3.   <package id="Autofac" version="3.5.2" targetFramework="net45" />  
  4.   <package id="AutoMapper" version="3.2.1" targetFramework="net45" />  
  5.   <package id="EntityFramework" version="6.1.1" targetFramework="net45" />  
  6.   <package id="Microsoft.AspNet.Cors" version="5.2.2" targetFramework="net45" />  
  7.   <package id="Microsoft.AspNet.Identity.Core" version="2.0.1" targetFramework="net45" />  
  8.   <package id="Microsoft.AspNet.Identity.Owin" version="2.0.1" targetFramework="net45" />  
  9.   <package id="Microsoft.AspNet.Razor" version="3.2.2" targetFramework="net45" />  
  10.   <package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" />  
  11.   <package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net45" />  
  12.   <package id="Microsoft.AspNet.WebApi.Cors" version="5.2.2" targetFramework="net45" />  
  13.   <package id="Microsoft.AspNet.WebApi.OData" version="5.2.2" targetFramework="net45" />  
  14.   <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.2" targetFramework="net45" />  
  15.   <package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.2" targetFramework="net45" />  
  16.   <package id="Microsoft.Data.Edm" version="5.6.2" targetFramework="net45" />  
  17.   <package id="Microsoft.Data.OData" version="5.6.2" targetFramework="net45" />  
  18.   <package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" />  
  19.   <package id="Microsoft.Owin.Host.SystemWeb" version="2.1.0" targetFramework="net45" />  
  20.   <package id="Microsoft.Owin.Security" version="2.1.0" targetFramework="net45" />  
  21.   <package id="Microsoft.Owin.Security.ActiveDirectory" version="2.1.0" targetFramework="net45" />  
  22.   <package id="Microsoft.Owin.Security.Cookies" version="2.1.0" targetFramework="net45" />  
  23.   <package id="Microsoft.Owin.Security.Facebook" version="2.1.0" targetFramework="net45" />  
  24.   <package id="Microsoft.Owin.Security.Google" version="2.1.0" targetFramework="net45" />  
  25.   <package id="Microsoft.Owin.Security.Jwt" version="2.1.0" targetFramework="net45" />  
  26.   <package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.1.0" targetFramework="net45" />  
  27.   <package id="Microsoft.Owin.Security.OAuth" version="2.1.0" targetFramework="net45" />  
  28.   <package id="Microsoft.Owin.Security.Twitter" version="2.1.0" targetFramework="net45" />  
  29.   <package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net45" />  
  30.   <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />  
  31.   <package id="Owin" version="1.0" targetFramework="net45" />  
  32.   <package id="RazorEngine" version="3.4.1" targetFramework="net45" />  
  33.   <package id="System.IdentityModel.Tokens.Jwt" version="3.0.2" targetFramework="net45" />  
  34.   <package id="System.Spatial" version="5.6.2" targetFramework="net45" />  
  35.   <package id="WindowsAzure.MobileServices.Backend" version="1.0.447" targetFramework="net45" />  
  36.   <package id="WindowsAzure.MobileServices.Backend.Entity" version="1.0.447" targetFramework="net45" />  
  37.   <package id="WindowsAzure.MobileServices.Backend.Tables" version="1.0.447" targetFramework="net45" />  
  38.   <package id="WindowsAzure.ServiceBus" version="2.3.4.0" targetFramework="net45" />  
  39. </packages> 

Returning back to the “Updates”, we will see the following Nuget packages that we can update, but for the reasons we saw, it is not possible to update all.

Manage Nuget
                                                Image 11 Manage Nuget Packages

Conclusion

In conclusion, each developer should be aware of the dependencies among Nuget packages and that more than one package can depend on the same Nuget package but for different versions, this mean it is necessary to keep the versions used by each one.

Up Next
    Ebook Download
    View all
    Learn
    View all