Create Cross Platform Mobile App with .NET Standard 2.0

Cross Platform Mobile App

Mobile Apps is a trending today. Today, we are going to learn how to create a Cross Platform Mobile App,with the latest .NET Standard 2.0 in C#! It’s just easy and fast! .NET Standard 2.0 has provided more APIs than ever now!

Pre-requisite

  • In order to start the development, we need Visual Studio 2017 for Windows installed with Xamarin Cross-Platform components & all necessary platform-specified SDK, such as Android SDK/ Windows SDK. If you don’t have it yet, download Community Version for FREE today!
  • Xamarin.Forms 2.4 or above.

Visual Studio

 

Why do we need to use .NET Standard 2.0?

  • Defines uniform set of BCL APIs for all .NET implementations to implement, independent of workload.
  • Enables developers to produce portable libraries that are usable across .NET implementations, using this same set of APIs.
  • Reduces or even eliminates conditional compilation of shared source due to .NET APIs, only for OS APIs.

In nutshell, the lower version supports more platforms while the higher version supports more APIs.

For this tutorial, we will learn how to create Xamarin Cross Platform app with .NET Standard. If you are looking to create app with PCL, you may click here to learn how to create one in just 6 steps! (If you are using Visual Studio 2017 15.5 and above, you don’t have to do manual conversion from PCL project to .NET Standard project)

Want to understand which .NETStandard version is suitable for you here.

 

Let’s begin with .NET Standard 2.0…

  1. After you have installed Visual Studio 2017 (VS2017) with Cross-Platform development, launch it.
  2. We will now to create a Cross-Platform mobile app that is running on Android, iOS & Windows UWP app. Let’s Select File -> New -> Project….
  3. Select Cross-Platform -> Cross Platform App (Xamarin) -> Enter your App Name and then Hit OK.
    hmheng - Xamarin with .NET Standard 2.0
  4. To make the following migration steps simple, we shall select Blank App with Xamarin.Forms & PCL now. Then click OK.
    hmheng - Xamarin with .NET Standard 2.0
  5. While creating the platform-specified projects, VS2017 will ask you for a UWP Minimum Target Version & select Build 16299 (Minimum for .NET Standard 2.0).
    hmheng - Xamarin with .NET Standard 2.0
  6. Now, your app is ready to be compiled & running on your PC/Android. But, we want to develop with .NETStandard 2.0!
    hmheng - Xamarin with .NET Standard 2.0
  7. So, in order to migrate it from PCL to .NETStandard 2.0, we need to right click Solution at Solution Explorer.
    hmheng - Xamarin with .NET Standard 2.0
  8. Now, we will add a new .NETStandard 2.0 project to replace PCL. Right click the Solution, Select Add -> New Project….
    hmheng - Xamarin with .NET Standard 2.0
  9. Select .NET Standard -> Class Library -> Enter <namespace>.Core. Then click OK.
    hmheng - Xamarin with .NET Standard 2.0
  10. We should have .NET Standard project now, so we can pull all necessary files from PCL to .NET Standard project.
    hmheng - Xamarin with .NET Standard 2.0
  11. Furthermore, we can delete the Class1.cs since we do not need it.
    hmheng - Xamarin with .NET Standard 2.0
  12. Now, we can delete PCL. Right click the PCL project in Solution Explorer. Remove it from solution.
    hmheng - Xamarin with .NET Standard 2.0
  13. After deleting PCL project, we need to install Xamarin.forms & .NETStandard library from NuGet.
    hmheng - Xamarin with .NET Standard 2.0
  14. First, let’s search for & install .NETStandard library to all other projects.
    hmheng - Xamarin with .NET Standard 2.0
  15. Secondly, to add Xamarin Forms to our newly created .NETStandard project, search for Xamarin.Forms & install to the project.
    hmheng - Xamarin with .NET Standard 2.0
  16. However, you may get error of duplication while trying to build. Therefore, we need to remove following line from the project’s .csproj file.
    hmheng - Xamarin with .NET Standard 2.0
  17. Then, we add reference to .NETStandard project to all other platform specific to tell all other projects “Hey, I am your new UI project!”. Right click Project -> Add -> Reference
    hmheng - Xamarin with .NET Standard 2.0
  18. Tick the newly created project and click OK. Repeat the same for Android, UWP & iOS.
    hmheng - Xamarin with .NET Standard 2.0
  19. Finally, let’s connect our phone & re-deploy again!
    hmheng - Xamarin with .NET Standard 2.0

 

Xamarin.Forms with .NET Standard 2.0

 

Extras

In case you need to install some PCL libraries to your new .NETStandard’s Xamarin Forms, you will need to add this to <namespace>.Core.csproject.

  <PropertyGroup>

<TargetFramework>netstandard2.0</TargetFramework>

    <PackageTargetFallback>$(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8</PackageTargetFallback>

</PropertyGroup>

Extra Xamarin.Forms with .NET Standard 2.0

 

Click here to get an offline copy!

Need a extra jump start? Download source code from Github now!

You may also want to learn how to make your app communicating with IoT Device or other network capable peripherals @ latest tutorial  .


Don’t forget to follow me @
Twitter: @hmheng
More slides @ SlideShare: https://www.slideshare.net/HiangMengHengMarvin
Blog: http://hmheng.pinsland.com

You may also like...

7 Responses

  1. November 2, 2017

    […] to learn how to create a mobile app first, so you may refer to our previous post – “Create Cross Platform Mobile App with .NET Standard 2.0“. Secondly, you may also need Visual Studio 2017 with cross platform development component […]

  2. November 6, 2017

    […] LUIS, Language Understanding Intelligent Service, is an AI service that understands your intention and involving entities in what you say or type. We have learnt how to create an LUIS app @ http://www.luis.ai. Today, we are going to learn how we can integrate it to our mobile app that we created using .NETStandard 2.0 previously. […]

  3. November 11, 2017

    […] Created a Xamarin mobile app […]

  4. November 21, 2017

    […] Secondly, we need to create a Xamarin cross platform mobile app with .NET Standard 2.0. […]

  5. November 24, 2017

    […] Created a Xamarin mobile app […]

  6. November 29, 2017

    […] Created a Xamarin mobile app […]

  7. December 5, 2017

    […] @ just almost 10 seconds to load a solution, Xamarin Live Player, .NET Standard Xamarin template (rather than our old manual tweak) and improved workflow for publishing web app to Azure […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: