Click here to Skip to main content
15,880,905 members
Articles / Mobile Apps / Xamarin

Building 64-Bit Windows on ARM Apps with Xamarin

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
23 Jun 2022CPOL6 min read 4.7K   1  
This article will show how to create a simple but complete WoA-native MAUI application.

Windows on ARM enables a new generation of fast, lightweight computing solutions. Windows apps (including Xamarin apps) can run under emulation on the new platform, but to truly take advantage of the platform’s power, you want to create native apps.

In previous articles, you have seen that the emulation mode for AArch64 is excellent, but inevitably, it is slower than native applications. So, we will explore how we can create a native AArch64 Xamarin application to enjoy the full power of AArch64.

In the same series, we have already published Today's Best Practices for Migrating Windows apps to Windows on Arm, Migrating Windows Apps to Windows on Arm with WPF and .NET 6, and Building a Native Windows on Arm App with WinUI 3.

What is Xamarin?

Xamarin is an open-source app platform for building modern applications with C# and .NET that can run everywhere. Usually, this means that it runs on any version of Windows, but in this case, the meaning is broader. A Xamarin application can also run on Android and iOS from a single shared codebase. This includes Windows on AArch64.

Image 1

This article uses the XamlSamples repository on GitHub and deploys a natively compiled application on an AArch64 laptop. By deploying on AArch64, you make the best use of the processor. It is possible to run a simulation mode, but that can be as much as ten times slower.

Prerequisites

You need some knowledge of Visual Studio 2022 to follow the article. However, the article's focus is on deployment, so you do not need previous knowledge of C# or XAML.

Setting up the Dev Environment

Before you can start to develop, you must set up your development environment. Now is the time to install Visual Studio 2022 (VS2022) if you have not yet done so. The free community version is sufficient for this article and it runs fluidly alongside previous versions of Visual Studio, so fear not.

Installing VS2022 also automatically installs the .NET 6 SDK. This is preferable to .NET 5, which reached its end of support on May 8, 2022.

After downloading, start the setup program and select the Mobile development with .NET workload, which includes Xamarin development. You can optionally add other workloads.

Image 2

If you have already installed VS2022, verify that you installed this workload by starting the Visual Studio Installer. This enables you to add more components to your VS2022 installation if needed.

Cloning the Application

Open VS2022 and select Clone a repository on the start page.

Image 3

On the next page, enter the Git repository URL. For the demo application, use https://github.com/xamarin/xamarin-forms-samples. The Path must point to an empty folder on your computer. Here is what it looks like:

Image 4

Click Clone to copy the repository to your machine. Visual Studio opens and displays all files in the folder view.

In the folder view, double-click the Xuzzle solution. Now you see the Solution Explorer:

Image 5

There are three platforms for your Xamarin application. Right-click Xuzzle.UWP and choose Set as startup project.

Run the project on your PC and start to play Xuzzle. Take a quick break and enjoy the game.

Deploying to AArch64

You now have an application running perfectly on your development machine in dev environment. Next, you can make it run on the AArch64 device.

To start, deploy to your development environment.

Then, select Release mode for the project. Otherwise, you deploy the Debug version with all of its unnecessary overhead. However, deploying the Debug version is a suitable choice if you want to debug your application remotely on the AArch64 device.

Next, right-click the Xuzzle.UWP project and select Publish > Create App Packages.

For the distribution method, there are two possibilities:

  • Microsoft Store — Use this if you want to deploy the application to the Microsoft Store. For our testing purposes, this is not an option.
  • Sideloading — Use this to create an application that you can install on target machines without passing through the Microsoft Store. You can use this for a company's private applications, and in our case, for quick testing.

Select Sideloading and click Next.

On the next page, you must select a certificate. If you do not have a certificate handy, you can create one by clicking Create.

To create a self-signed test certificate, enter a Publisher Common Name (such as your company name) and a password. Click OK. This creates a new certificate and imports it to the certificate store.

Image 6

Take note of the password because you will need it to install the certificate on the AArch64 device.

On the next page, select Yes to use the current certificate and accept all the defaults.

Now, select x64 and ARM. If you want to try the application on an x86 device, keep that checkbox selected as well. Click Create to start a new build and publish the application.

First, test if it works on your machine. Open your Windows Start menu and search for "Xuzzle." It should be on the list and ready to play again.

Deploying to the AArch64 Device

Setting up a shared folder is not a mandatory step. You can transport the package folder to the AArch64 device in any way that you prefer. But, this way, the effort is minimal and easy to repeat. Rebuilding the solution on your development box is sufficient.

Setting up a Shared Folder

Set up a shared folder from the dev machine. You can do this in File Explorer by right-clicking the folder at the end of this path:

\Xuzzle\Xuzzle\Xuzzle.UWP\AppPackages\Xuzzle.UWP_1.0.0.0_Debug_Test > Properties > Sharing > Advanced Sharing

Image 7

If you prefer to do this from a command prompt, open a shell in administrator mode and type:

net share Xuzzle.UWP=C:\_projects\Blog\xamarin-forms-samples\Xuzzle\Xuzzle\Xuzzle.UWP

On the AArch64 device, connect to the folder with the net use command:

net use x: //DevmachineName/Xuzzle.uwp

You now see a new X drive in File Explorer.

Installing the Certificate

Recall that you had to create a certificate to sign the application. You must install this trusted certificate on the AArch64 device. The easiest way to do this is by using a command prompt in administrator mode and typing:

certutil.exe -addstore TrustedPeople .\Xuzzle.UWP_1.0.0.0_x64_arm_Debug.cer

Installing the Xamarin Application

Now that everything is in place on the AArch64 device, you are ready to install the application.

At the administrator command prompt, go to the AppPackages\Xuzzle.UWP_1.0.0.0_Debug_Test folder. There is a PowerShell script called install.ps1. Running this script locates all the necessary dependencies and then installs the application.

Now you can play once again.

Conclusion and Next Steps

This article discussed how to set up your development machine to build Xamarin applications and deploy the applications to an AArch64 device for testing. Following these guidelines, you can deploy your applications without much trouble.

But this is not all you can do. Microsoft uses Xamarin as the basis for MAUI, its new cross-platform UI Toolkit. Although Microsoft has not released MAUI yet, you can port most Xamarin Forms apps — like the one above — to MAUI with very few changes. So, by getting up to speed on Xamarin now, you're preparing yourself for the future of high-performance .NET apps on 64-bit ARM-powered devices.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Faq.be bvba
Belgium Belgium
Gaston Verelst is the owner of Faq.be, an IT consultancy company based in Belgium (the land of beer and chocolate!) He went through a variety of projects during his career so far. Starting with Clipper - the Summer '87 edition, he moved on to C and mainly C++ during the first 15 years of his career.

He quickly realized that teaching others is very rewarding. In 1995, he became one of the first MCT's in Belgium. He teaches courses on various topics:
• C, C++, MFC, ATL, VB6, JavaScript
• SQL Server (he is also an MSDBA)
• Object Oriented Analysis and Development
• He created courses on OMT and UML and trained hundreds of students in OO
• C# (from the first beta versions)
• Web development (from ASP, ASP.NET, ASP.NET MVC)
• Windows development (WPF, Windows Forms, WCF, Entity Framework, …)
• Much more

Of course, this is only possible with hands-on experience. Gaston worked on many large scale projects for the biggest banks in Belgium, Automotive, Printing, Government, NGOs. His latest and greatest project is all about extending an IoT gateway built in MS Azure.

"Everything should be as simple as it can be but not simpler!" – Albert Einstein

Gaston applies this in all his projects. Using frameworks in the best ways possible he manages to make code shorter, more stable and much more elegant. Obviously, he refuses to be paid by lines of code!

This led to the blog at https://msdev.pro. The articles of this blog are also available on https://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=4423636, happy reading!

When he is not working or studying, Gaston can be found on the tatami in his dojo. He is the chief instructor of Ju-Jitsu club Zanshin near Antwerp and holds high degrees in many martial arts as well.

Gaston can best be reached via https://www.linkedin.com/in/gverelst/.


Comments and Discussions

 
-- There are no messages in this forum --