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.
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.
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.
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.
- Select Users and Access, and then select the API Keys tab.
- Click Generate API Key or the Add (+) button.
- Enter a name for the key. The name is for your reference only and is not part of the key itself.
- Under Access, select the role for the key.
- Click Generate.
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.
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.
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).
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.
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.
Fast forward to the deployment, you have to check the configuration of the project for Apple. Open the Properties of your project.
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.
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.