Xamarin Visual Studio Templates

xamarin visual studio templates

Overview

In latest posts I have been setting up ASP.NET Core microservices, trying to build front-end build pipeline with gulp and manually inject bootstrap css. All of this of course on Ubuntu. As Xamarin joined Microsoft family, I wanted to test how it can be used. However when you install everything there is a lot of Xamarin Visual Studio templates. Let’s try to see what their purpose is.

Code

I have decided to create projects from each template. You can find the code on my GitHub.

xamarin visual studio templates

Some of these projects don’t build, but that’s not an issue for now. I just wanted to see what is there and which one should be used to write my mobile app.

In Visual Studio we can create:

  • Visual C# -> Android
  • Visual C# -> iPhone/iPad
  • Visual C# -> Cross Platform -> Native Portable
  • Visual C# -> Cross Platform -> Native Shared
  • Visual C# -> Cross Platform -> Forms Portable
  • Visual C# -> Cross Platform -> Forms Shared
  • Universal -> iOS
  • Windows -> Universal
  • Windows -> Windows 8 -> Universal Windows 8.1

xamarin visual studio templates

I’m working in Microsoft Galaxy for years right now. I got used to the fact that there is just one true ORM, just one logging library, just one way to write web apps… Blame you Java World.

Xamarin Visual Studio Templates

Shared vs Portable

First thing that you need to understand is a difference between Shared and Portable libraries. Pretty well approach is described in Xamarin help.

  • shared projects use compiler directives if you want to write some platform specific code. This means that you will have just one project for every platform
  • portable libraries can define interface that will be implemented in platform specific. This means that you will have one portable project for every platform plus one native project per device if you need anything device specific (plus some DI logic to handle injection)

From my perspective this transforms into:

  • shared project are simple but not best practice (compiler directives) => use it for small/home projects
  • portable libraries are more complex but according to best practices => use it in professional applications

Native Applications

With Xamarin installed on your machine, you have an option to create native applications in C#. These are the templates:

  • Visual C# -> Android (native android Application)
  • Visual C# -> iPhone/iPad (native iPhone, iPad application)
  • Universal -> iOS (native for iPhone and iPad)
  • Windows -> Universal (native for Windows 10 and Windows Phone 10)
  • Windows -> Windows 8 -> Universal Windows 8.1 (native for Windows 8.1 and Windows Phone 8.1)

Sounds simple. In this case you will need to create UI using phone specific libraries (as on iPhone/WP/Android)

Forms Applications

What are Forms? Xamarin describes them pretty well:

“Use the same language, APIs and data structures to share an average of 75% of app code across all mobile development platforms. Build user interfaces with Xamarin.Forms and share nearly 100%.”

Concept of Forms is that you can create one UI Xaml that will be shared between multiple platforms. You still have a project per device, due to all manfiest, debug, runtime, etc… but in theory you have only one UI that will be transformed to device native controls.
So not, you are not using some dummy controls. You will be using official iPhone/Android controls, but you will have one source UI Xaml.
Looks very promising.

Cross Platform

We are left with all CrossPlatform templates. Let’s see what they have created:
xamarin visual studio templates

As you can see, these Xamarin visual studio templates are not something new. They are just creating all projects that you need to have in each approach: Forms Portable, Forms Shared, Native Portable, Native Shared.

Summary

Xamarin looked a bit complex to start but now it’s kind of clear. Xamarin Visual Studio Templates are giving so many options but, you need to make a choice to go with

  • Portable (recommended) or Shared (not recommended) approach in first place.
  • Then you need to choose are you going with Forms or Native.

I’ll need to explore Forms more in next posts. They look promising: only one UI, so only one place to change, however I haven’t yet met really universal library.

One thought on “Xamarin Visual Studio Templates

Leave a Reply

Your email address will not be published. Required fields are marked *