DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. Xamarin Forms and .NET Standard - Getting Started

Xamarin Forms and .NET Standard - Getting Started

Learn about the advantages of Xamarin Forms for cross-platform app development and see how to get started using it with .NET Standard.

Michele Ferracin user avatar by
Michele Ferracin
·
Jan. 04, 18 · Tutorial
Like (6)
Save
Tweet
Share
12.49K Views

Join the DZone community and get the full member experience.

Join For Free

In this blog post, we're going to lay the basis for future posts about Xamarin Forms. We'll explore briefly what's Xamarin Forms and why it's so powerful. Then we'll talk about .NET Standard and we'll understand why it's a very big achievement for the .NET ecosystem.

Xamarin Forms

Xamarin Forms is an API to develop cross-platform apps for iOS, Android, and Windows from a single shared C# codebase. It's not a one-size-fits-all technology, but it's very useful when code sharing is more important than a custom UI for every platform. If we are Windows developers, we'll love Xamarin because it allows us to reuse all our hard-earned skills like XAML, binding, MVVM, and so on. If we need device-specific features, we can access them, too.

.NET Standard

The .NET Standard is a formal specification of .NET APIs that are intended to be available on all .NET implementations. The motivation behind the .NET Standard is establishing greater uniformity in the .NET ecosystem, enabling developers to produce portable libraries that are usable across .NET implementations, using this same set of APIs.

We can look at .NET Standard as a specification of .NET APIs that make up a set of contracts. These contracts are implemented in each .NET implementation. This enables portability across different .NET implementations, allowing our code to run everywhere.

A Fresh Start

Before getting started, make sure you've run the Visual Studio Installer and have upgraded to the latest stable release of Visual Studio. At the time of this writing, I have this setup:

Image title

The first step to creating a cross-platform Xamarin Forms app is to create a new project with Visual Studio.

  1. File
  2. Project
  3. Visual C# -> Cross-Platform
  4. Cross-Platform App (Xamarin.Forms)
  5. We give a name to the Project (GettingStarted) and press OK.

When we press OK, a new window appears. We choose blank-app as a template, Xamarin.Forms as the UI Technology, and .NET Standard as the Code Sharing Strategy (read here about Shared Projects).

When we hit OK, Visual Studio works for a while and prepares a new solution for us.

Anatomy of a Cross-Platform Solution

The new solution is composed of four projects:

  • The shared code project (red rectangle). The output of this Project is a dll that can be used in every implementation of the .NET Standard version of our choice (.NET Standard 2.0 is the default setting). We want the big part of our code inside this Project to minimize differences between the three flavors of our app.
  • The platform-specific projects (Android, iOS, Windows). The output of these projects is the app for the specific target Platform. In these projects we implement specific functions/UI/services for the target device; to start a phone call, for example, the code is different for every OS and we need to write our code for each platform and not in the shared Project.

To check that everything is ok we try to build and run the Android version of the App in an emulator. We set the Android Project as the Startup Project with right click in the Solution Explorer and then Set as Startup Project.

We choose our favorite Android Virtual Device (AVD - I created a custom configuration) and then we press Play/Run.

After compiling and launching the AVD, Visual Studio will deploy and run the app.

We can do the same thing with the other two device-specific projects. Keep in mind that to build the iOS Project you need a Mac on your network.

It's done!

TL;DR

In this post we created a Xamarin Forms Project with the Visual Studio template, we learned the purpose of Xamarin Forms and .NET Standard. Now we have the basics to develop the app of our dreams.

In the future posts, we'll evolve this app introducing MVVM and other concepts.

Reference

  • Xamarin official website ( https://developer.xamarin.com/)
  • Microsoft documentation ( https://docs.microsoft.com/en-us/dotnet/standard/net-standard)
xamarin.forms xamarin Form (document) .NET app Cross platform

Published at DZone with permission of Michele Ferracin, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Future of Cloud Engineering Evolves
  • Java Development Trends 2023
  • Kotlin Is More Fun Than Java And This Is a Big Deal
  • A Complete Guide to AngularJS Testing

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: