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.
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.
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.
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:
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:
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.
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
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.