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!
- 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.
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…
- After you have installed Visual Studio 2017 (VS2017) with Cross-Platform development, launch it.
- 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….
- Select Cross-Platform -> Cross Platform App (Xamarin) -> Enter your App Name and then Hit OK.
- To make the following migration steps simple, we shall select Blank App with Xamarin.Forms & PCL now. Then click OK.
- 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).
- Now, your app is ready to be compiled & running on your PC/Android. But, we want to develop with .NETStandard 2.0!
- So, in order to migrate it from PCL to .NETStandard 2.0, we need to right click Solution at Solution Explorer.
- Now, we will add a new .NETStandard 2.0 project to replace PCL. Right click the Solution, Select Add -> New Project….
- Select .NET Standard -> Class Library -> Enter <namespace>.Core. Then click OK.
- We should have .NET Standard project now, so we can pull all necessary files from PCL to .NET Standard project.
- Furthermore, we can delete the Class1.cs since we do not need it.
- Now, we can delete PCL. Right click the PCL project in Solution Explorer. Remove it from solution.
- After deleting PCL project, we need to install Xamarin.forms & .NETStandard library from NuGet.
- First, let’s search for & install .NETStandard library to all other projects.
- Secondly, to add Xamarin Forms to our newly created .NETStandard project, search for Xamarin.Forms & install to the project.
- However, you may get error of duplication while trying to build. Therefore, we need to remove following line from the project’s .csproj file.
- 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
- Tick the newly created project and click OK. Repeat the same for Android, UWP & iOS.
- Finally, let’s connect our phone & re-deploy again!
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.
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 @
More slides @ SlideShare: https://www.slideshare.net/HiangMengHengMarvin