Deploy MAUI apps on a real device

Deploy MAUI to a real device

Developing applications with NET8 MAUI, we want to deploy and test apps on real devices. The configuration for Apple is not easy and requires a lot of steps. Microsoft documentation is not updated with the latest version of Visual Studio and the Apple Developer portal.

So, here are my notes on how to do it without wasting time.

Windows and Windows

First, the easy part. Run and test applications from Visual Studio to Windows – assuming you are using Visual Studio on Windows (Visual Studio for Mac is not available anymore) – you have just to press run. Sometimes, Visual Studio can require you to deploy the application to your machine before running it.

Android

For Android, the deployment is quite easy too. You can connect your Android device to the machine with Visual Studio and then deploy the application to the device when Visual Studio recognizes it. Another solution is to create an instance of a simulator.

Example of a list of Android Emulators
Example of a list of Android Emulators

If you can’t see the device in the list, you can try to restart adb or check the minimum API version of the application. If the application is set to use a higher API of your device, the device won’t be listed.

Connect your account on Xcode

First, I have to add my account in Xcode on my iMac. For that, open Xcode and then click on Settings under the main menu. I see this window (in this case you see my account). Add your account by clicking the + at the bottom left. Remember to buy an account as a developer from Apple.

Account window in Xcode - Deploy MAUI apps on a real device

From here, click on Download Manual Profiles. Then, click on Manage Certificates and create a certificate for development and another one for distribution.

Login with Apple account in Visual Studio

Now, the first thing to do is connect your Visual Studio with Apple. The steps for Visual Studio are explained in the Microsoft documentation but it is not updated with the last version of Visual Studio or the new Apple Developer website. So, here are some hints.

You will need to be Paired to a Mac build host before proceeding

Under the menu Tools > Options, search for Apple Accounts. Then, click on Add. Now, you should see a new window like the following screenshot.

Individual Account configuration in Visual Studio - Deploy MAUI app on a real device
Individual Account configuration in Visual Studio

The info to insert are coming from the Apple Developer website and in order to generate keys, you must have an Admin account in App Store Connect. You may generate multiple API keys with any roles you choose.

Log in to App Store Connect to generate an API key to use with the App Store Connect API.

  1. Select Users and Access, and then select the API Keys tab.
  2. Click Generate API Key or the Add (+) button.
  3. Enter a name for the key. The name is for your reference only and is not part of the key itself.
  4. Under Access, select the role for the key.
  5. Click Generate.
Users and Access - Integration to create the API key for Visual Studio - Deploy MAUI app on a real device
Users and Access – Integration to create the API key for Visual Studio

The new key’s name, key ID, a download link, and other information appear on the page. Fill out the form in Visual Studio using the info from this page:

  • Name is your name (this is my guess)
  • Issuer ID is displayed after the API key is generated and you can copy it from the page
  • Key ID copied from the table in the page
  • Private key path select the path where the file is

Here is an example of the table with the API key.

Example of a API key created (in this case only for display) - Deploy MAUI apps on a real device
Example of an API key created (in this case only for display)

Create an application in Xcode

Now, the next part is to create a dummy application in Xcode on your Mac to have all the required provisionings and certificates on your machine.

For that, launch Xcode and create a new App.

Xcode: select a new project - Deploy MAUI app on a real device
Xcode: select a new project

Then, fill out the form adding the Project Name you want to use but the most important thing to type carefully is the Organization Identifier. Project Name and Organization Identifier together are the ApplicationId (Bundle ID for Apple or Package name for Android).

Xcode: select the product name - Deploy MAUI app on a real device
Xcode: select the product name

So, you are ready to select the Team and get your certificate. Only with those configurations, you will be able to deploy your applications on real devices.

Xcode: signing & Capabilities - Deploy MAUI apps on a real device
Xcode: signing & Capabilities

Deploy to a real device from Visual Studio

The first important action is to connect Visual Studio to the Mac machine (if you haven’t done so yet). If the connection is established, you see a chain on the Mac machine.

Pair to Mac

Fast forward to the deployment, you have to check the configuration of the project for Apple. Open the Properties of your project.

iOS Bundle Signing for a project in Visual Studio
iOS Bundle Signing for a project in Visual Studio

Here you have 3 important settings:

  • Scheme: Manual Provisioning
  • Signing identity: Developer (Automatic)
  • Provisioning profile: Automatic

Those settings are working for deployment to a simulator or a real device.

Visual Studio raises an error MT1045 Failed to execute when deploying a MAUI app to a real device

Visual Studio is connected to my iMac and the iPhone to the iMac. The deployment on the Simulator is working fine. When I deploy it on the iPhone, Visual Studio shows this error

error MT1045: Failed to execute ‘devicectl’: ‘devicectl -j /var/folders/dm/bwmxpbzn6bvdsyy73c_b453w0000gn/T/tmpBkAavG.tmp device install app –device “Enrico???s iPhone” /Users/enrico/Library/Caches/Xamarin/mtbs/builds/LanguageInUse/1fa03704bb15e35c6f47a701d9d92131e3e0740198296a93338bb3c829bc9cf7/bin/Debug/net8.0-ios/ios-arm64/device-builds/iphone15.2-17.3.1/LanguageInUse.app’ returned the exit code 1. 0

In the Output window, I also notice this error:

NSLocalizedFailureReason = This app cannot be installed because its integrity could not be verified. NSLocalizedRecoverySuggestion = Failed to install embedded profile for com.languageinuse.app : 0xe800801f (Attempted to install a Beta profile without the proper entitlement.)

I like to highlight that I deployed the application on the iPhone roughly a month ago without issues. I got the Provisioning Profile from the Apple Store and so on.

The configuration on Visual Studio for iOS is the following.

Project properties in Visual Studio
Project properties in Visual Studio

Solution

First, that may be because you do not add the UDID of your iPhone device in the provisioning file. You may refer to Add a device and update your provisioning file to contain your new iPhone device.

The other option is that for some reason the provisioning profile has changed. So, you have to download the new one in order to deploy it on a real device.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.