Xamarin

Building Mobile Apps Using Xamarin.Forms with .NET Standard

by Friday, June 30, 2017 comments
The .NET Standard Library is a formal specification of .NET APIs that are intended to be available on all .NET runtimes. You can understand another way its expanded, Portable Class Library. It is a single library with a uniform API for all .NET Platforms including .NET Core. You just create a single .NET Standard Library and use it from any runtime that supports .NET Standard Platform.

You can refer following table lists all the versions of .NET Standard and the platforms supported



In this article, you will learn how to create mobile cross platform application using Xamarin Forms with .NET Standard libraries and maximize code sharing.

Create New Xamarin Forms:

Let’s start create new Xamarin Forms application, In Windows machine > Go to Run (Windows key +R) > type Devenv.exe for open Visual Studio and select New project from File menu > New Project (ctrl +Shift+N) or click More project template from VS Start screen.



Click on Ok > You will get following screen. Select Blank App > Select Xamarin Forms UI Technology > Select Code sharing as PCL or Share Project and click on Ok



After click on Ok, VS will automatically create PCL,iOS,Android ,UWP projects .

Create .Net Standard Class library

You can follow below steps for create .Net Standard library,

Right Click on solutions > Add new project > Create Class library (.Net Standard) that targets .net Standard and click on Ok


Install Xamarin Forms in .Net Standard library:

The Xamarin.Forms 2.3.5-prerelease will support with .NET Standard. Right Click on .net Standard library > Select on Manage Nuget package



Select on Browse tab > Search text ‘ Xamarin.Forms ‘ > Select Include prerelease and select Xamarin Forms and click on Install


Customize the Application:

You can follow below steps for customize the platform specific project and .net standard library.

Step 1: 

 Right Click on .Net Standard library > Click on Add Item > Select Cross -Platform >Forms Blank Content Page Xaml > Provide name as MainPage.xaml


Step 2: 

You can add UI design as per your requirement in MainPage.xaml .

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DotNetStandard.MainPage">
<Label Text="Welcome to Xamarin.Forms Apps with .NET Standard!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</ContentPage>

Step 3:

 Copy App.cs and App.xaml from PCL or Shared project and past into .net Standard library and change the namespace from xaml and c# page



Step 4: Remove Shared or PCL Project and Remove PCl project reference from all iOS,Android,UWP project. Now solution look like below


Step 5: 

Add your .Net Standard class library reference to iOS,Android,UWP project.

Step 6:

 Change namespace from following project

In UWP project, updated the namespace from mainPage.cs

LoadApplication(new DotNetStandard.App());

In Android Project , Update the namespace from Main Activity

LoadApplication(new DotNetStandard.App());

In iOS Project , Update the namespace from Appdelegate

LoadApplication(new DotNetStandard .App());

Step 6:

 If you get following error while build the project



You can follow below for resolution Right Click on Xaml page > Select property and Build Action Should be Embedded Resource


Run the Application:

You can run the application (iOS,Android ,Windows) to all the platform



Summary

In this article, you learned how to create mobile cross platform application using Xamarin Forms with .NET Standard libraries.

If you have any questions/ feedback/ issues, please write in the comment box.




SJ
Suthahar Jegatheesan

Senior Solutions Architect · Microsoft Azure, AI & Mobile. Author of the Xamarin Q&A Book.

2 comments:

sponsored

What Colleagues Say

“Suthahar is one of the most thorough and knowledgeable cloud architects I’ve worked with. His depth on Azure and ability to make complex mobile solutions work cross-platform is remarkable. He always delivers beyond expectations.”

AT Arun T. Senior Engineering Manager · Direct Manager

“I’ve followed Suthahar’s MSDEVBUILD blog for years — practical, deep, always current. Working alongside him confirmed what I suspected: he’s as sharp in person as on paper, and a genuinely generous mentor and architect.”

RK Rajesh K. Lead Developer · Mindtree

Certifications & Recognition

AZ-300 · Azure Architect Technologies AZ-301 · Azure Architect Design AZ-104 · Azure Administrator Associate AI-100 · Designing Azure AI Solutions DP-900 · Azure Data Fundamentals MCPD · Windows Phone Certified SAFe® 4 Scrum Master

Technical Expertise

☁ Cloud Platforms Microsoft Azure — Expert · 18 yrs App Services · AKS · Functions · Cosmos DB · APIM · Entra ID AWS & Google Cloud — Advanced
๐Ÿค– AI & Automation Azure OpenAI / GenAI — Advanced · 5 yrs RAG Pipelines · Bot Framework · Cognitive Services · Vision & Speech AI · ML.NET
๐Ÿ“ฑ Mobile Architecture .NET MAUI & Xamarin — Expert · 12 yrs Flutter · Native iOS/Android · Offline-First · Secure Storage & Auth
๐Ÿ”’ Identity & Security Microsoft Entra ID — Expert OAuth 2.0 · OIDC · Zero Trust · Conditional Access · RBAC · Key Vault

Speaking & Community

Microsoft User Group Malaysia Recurring speaker on Azure architecture, AI integration and .NET mobile development across Malaysia and APAC.
Global Azure Bootcamp — Chennai Presented “AI into Xamarin Mobile Apps” at GAB Chennai, part of the worldwide Global Azure community event.
AI & Azure OpenAI Community Events Workshops and live demos on RAG pipelines, AI agents and intelligent workflow automation since 2023.
Mobile & Cloud Workshops — Coimbatore Multi-day deep-dive sessions at GRG Computer Technology, KG Microsoft Innovation Center and RVS College of Arts and Science.
500+Blog Articles
50+Conference Talks
10K+Monthly Readers
30Public Repositories
3Continents Delivered
MSDEVBUILD Assistant Ask about Suthahar, Azure, AI or mentorship
Hi! I’m a simple FAQ bot for MSDEVBUILD. Tap a question below or type your own.