Microsoft has made major strides to take its development tools out of a Windows-only world, both for the applications you can create and the platforms they run on. The open source .Net development tools that Microsoft got when it acquired Xamarin two years ago are key to Microsoft’s cross-platform transformation.
That transformation is very much evident today, with much of the Xamarin’s tools folded into Microsoft’s Visual Studio development platform over the last year, and its MacOS Xamarin Studio rebranded as Visual Studio for Mac with additional features for working with Azure and .Net Core.
To support Microsoft CEO Satya Nadella’s focus on an “intelligent cloud and intelligent edge” mission, Xamarin’s cross-platform development strategy is key to delivering the edge elements of that vision. Microsoft’s mobile strategy has pivoted away from its own Windows Mobile OS (at least for now), and the company is now concentrating on delivering applications for the previously alien platforms iOS and Android. It’s a shift that also means bringing its developer ecosystem to new platforms – especially if it’s to deliver on its Project Rome vision of applications and content that migrate from device to device, letting your work follow you wherever you go.
Building for the new edge
The edge of the cloud is now predominantly mobile devices. Android hardware outnumbers Windows PCs, and Apple’s iOS now dwarfs its MacOS business. If you’re building business apps, you need to build cross-platform code, targeting a fleet of both managed corporate devices and the many personal devices that will be where we do much of our work. Customer-facing code is also likely to target those two main mobile platforms, along with desktop apps.
Microsoft’s .Net tools and languages have become the basis of Microsoft’s desktop PC strategy. Now with Xamarin, the C# and F# code you use to build Windows .Net and Universal Windows Platform (UWP) applications can form the basis of your mobile apps.
Keeping UI and business logic separate is key to taking advantage of Xamarin’s tools and controls; it means you can deliver device appropriate user interface elements using Xamarin’s native controls or through its cross-platform Xamarin.Forms components.
One of the key issues facing developers who are moving code from Windows to Xamarin is in how the two platforms approach Microsoft’s XAML UI layout technology. Although they mainly use the same names for controls and for display elements, there are many places where they differ. If you’re trying to bring Windows code into Xamarin’s own Forms, you’ve got the added workload of converting all your existing layout markup.
That layout conversion won’t be a problem soon, with Microsoft’s announcement of XAML Standard 1.0. Best thought of as a companion to the upcoming .Net Standard 2.0 library, XAML Standard will standardize markup so that layout code from Windows can easily be ported to iOS, Android, and even MacOS. A common XAML format should also help other .Net implementations support GUIs, giving you the option of adding UI to, for example, .Net Core applications running on Linux.
Delivering a common version of XAML will take some time, and although Microsoft is developing the new standard in the open on GitHub, it’s clearly a Microsoft project. You can suggest possible features and issues, but Microsoft has the final say on what goes into the standard. For now, it’s an in-house process, though it’s easy to see future releases coming through the .Net Foundation or a similar organization, with a wider set of stakeholders driving the standard.
Once XAML Standard is released, and Xamarin.Forms has been ported to the new markup, you’ll be able to build one UI that works across multiple platforms—and across multiple XAML layout engines. In practice, of course, you’ll need to optimize your layout for each target platform, with separate projects and builds. But instead of having to create an app UI from scratch, your XAML assets will be portable.
Write once, build and test everywhere
Code that runs on multiple platforms needs to be tested on those platforms. That can be a time-consuming process, especially if you’re delivering iOS apps. Having to push code from a Windows development PC to a Mac to compile and then push it to iOS takes time, time that can be better spent debugging your code.
One possible answer to the problem is Microsoft’s bundling of many of its and Xamarin’s cloud-hosted tools into its new Visual Studio Mobile Center. Using cloud-hosted build machines means you don’t need to invest in Mac hardware. Sure, Xamarin Test Cloud lets you test code on live hardware, across many devices and many OS variants. But Mobile Center is really for the final stage of app development, when you’re ready to go beyond simulators and finalize your code before delivering it to an app store.
Modern development environments have gone back to the idea of the REPL, the Read Eval Print Loop, where you can try out snippets of code without leaving your IDE. It’s an approach that works well when you’re trying out business logic or a local user experience. However, it struggles when you’re developing code for mobile devices. Apple’s Xcode playgrounds help when you’re building native code in Swift, but that’s not much help when working in Xamarin.
Play it again, Xam
Apple’s app store policies can make it hard to use an iPhone as a developer device, but Microsoft has come up with an innovative solution. The new Xamarin Live Player, available for both iOS and Android, acts as a host for snippets of code, with debugging tools that link a phone and a PC running Visual Studio. You pair PC and phone via an on-screen QR code, then you can deploy the code and run it on a device (with some limitations). It’s a good way to see how a page of XAML will render, or how a user interaction will work, without having to build and install an entire app. It also avoids downloading all the SDKs you’ll need for a final build, letting developers work on less-powerful hardware and with limited storage.
It’s important to note that this isn’t a way to deliver apps without going through either iOS’s App Store or Android’s Google Play. Code isn’t persistent and, because it runs through a local interpreter, performance is poor. Plus, your test device needs to be on the same Wi-Fi network as your development PC.
Still, what’s significantly improved is the build-and-test cycle. You can now try things out without worrying about wasting time building, deploying, and testing—again and again. Once you’re happy with your code, you can download the appropriate SDKs and start working with tools like Mobile Center to build and deliver your final app.
Microsoft’s cross-platform future depends on Xamarin. With Xamarin baked into Visual Studio, and with upcoming releases of .Net Standard and XAML Standard, it’s driving Windows development as well as delivering code on other platforms. Microsoft is now much more than a Windows company, and in time we’re likely to see the “W” disappear from UWP. You won’t build code for just Windows, you’ll build code that runs everywhere.