One Code To Rule Them All, but Why?

Windows: runs on more than 90% desktops, laptops, netbooks and nowadays it runs on kiosks, smart devices, phones and these days gaming console. However, developers always faced challenge to target all these devices and deliver ONE app, which can run on all these devices. There were differences in APIs, kernel, core services and what not.

When .NET was released, Microsoft tried to solve this problem by introducing .NET Framework on desktop and .NET Compact Framework – a subset of full .NET Framework *modified* for smart devices. Then, there was yet another .NET Framework for yet another class of devices called .NET Micro-Framework. So, developers had three different .NET Frameworks to target different class of devices, yet someone can’t just copy/paste code from one device app to another. Libraries compiled for one device may not work on another (e.g. app compiled for Windows Mobile *may* fail if ran on desktop – as both used to be PEs). But, for someone like me, it was a good start. I could write apps for mobile phones or desktop using the same language that I know i.e. C# or VB.NET.

Later, Microsoft introduced a very nice concept of Portable Class Libraries, which allowed developers to share code between various platforms.

image 

The limitation was, PCLs are binaries which give you ‘least common denominator’ of APIs available across platforms you selected. So, if you select .NET Framework and Windows 8, APIs which common to these two platform will be selected. And, if you wanted to do maximum code-reuse, your best bet is to follow MVVM like patterns, put models/view models in PCL and create app for views. So, the project structure will look like:

image

PCLs solve some of the issues in best possible way. But when it comes to Windows & Windows Phone, there are lot of similarities like UI, API set, programming model. Here we need some solution which can give maximum code reuse and go beyond PCLs.

Welcome to Universal Apps

image

Universal Apps allows you to build app with maximum code sharing which can work on Windows and Windows Phone (and Xbox in future). When you create Universal App, template creates 3 projects for you as shown below:

image

Now, you may say that it looks pretty similar to above mentioned solution which use PCLs.  Yes, it looks same, but there are internal differences:

When you create Universal App, you can share UI, Media, Code, XAML, etc.. using Shared Project. Now, Shared project allow you to share *code* between projects, whereas PCL allow you to share *binary* between projects. That also means, you can’t use #if.. #then compiler switches in PCLs and can’t write (or rather get benefit from) platform specific code. So, it also means that, when you build the project, you don’t get *.Shared.dll or something and it is not *referenced*, rather during build the code will be automatically included from shared project into individual projects. You can spot the difference in icon here.

image

With Universal App, you can share UI as well. In next screenshot you can see that there is almost no difference in Windows page and Windows Phone page.

image

image

Just tell me which one is which and I’ll give you a gift when we’ll meet next time Smile. Now rather I typing here, following slide will speak a lot:

image

After all this, if you *package* these projects, you get APPX which you can submit to the store.

This is certainly a nice move from Microsoft considering developer audience. For consumers, they can now buy app on desktop and can use it on phone. And for me this is true ‘ONE MICROSOFT’ Smile

There are many new announcements happened at //build/ to follow them and If you want to know more about Windows Phone 8.1 Features, Universal App FAQs, do visit blogs from my friends:

Namaste,

Mayur Tendulkar

Advertisements

Published by

Mayur Tendulkar

Working as a Program Manager for Xamarin in Microsoft. More details at: https://about.me/tendulkar

5 thoughts on “One Code To Rule Them All, but Why?”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s