After my experience starting a new project and still feel the pain, here I show you How to prepare a MAUI environment for your projects.
Table of contents
Configure macOS and iOS
Here the basic steps we follow in order to deploy an application using macOS to deploy to iPhone and iPad. As you know, you must have a macOS machine to build and deploy your applications to real devices or use the simulator.
The first step is the check on macOS is Xcode is installed. If not, you have to install from the Apple Store. When you run Xcode, you should have a screenshot like the following.
Add an Apple account
The first action to do is to register your Apple account in Xcode and Download Manual Profiles.
Configure your devices
Now, from the menu, choose Window and then Devices and Simulators.
In order to deploy an application on a real device, you have to register your device in Xcode from here. As you can see in the following screenshot, I want to pair my new iPhone.
When the registration is completed and your device pairs with your macOS computer, you should see something like in the following screenshot. If it is your first registration, you won’t have any apps attached.
Now, the next step is create a dummy project to test is we can deploy on a real device. Choose from the first splash screen, the option Create a new Xcode project.
Then, select App from the list and press Next. If you try to run the application on your real device, you can get this error:
The operation couldn’t be completed. Unable to launch com.puresourcecode.dummy because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user.Xcode
So, this is normal because you are not a trusted developers (basically you haven’t pay Apple for a certificate). For this reason, we have to move to the physical devices to accept yourself as a trusted developer.
Note: you can do the next steps only if your device is registered in Xcode. If not, you won’t see the options for the Developer mode.
Now, after the registration of your device in Xcode, you have to accept yourself as a trusted developer but before that you have to enable your device for the Developer Mode.
Enable Developer Mode
For that, go to the Settings of your device and look for Privacy and Security. If your device is connected to the macOS computer, you have the Developer Mode option. So, switch it ON.
Finally, you can trust yourself! Go the the Settings and then General. Here, you have the option VPN & Device Management. Click on that.
So, here you can see all the profiles that are installed in your device. Plus, a new entry for the Apple Development. This option is available only after the first failed deployment with Xcode (for this reason I created the dummy project earlier).
In the screenshot, you can see that my profile Apple Development: firstname.lastname@example.org (obviously you will have your account) under Developer App is not accepted yet. So, click on it and you see a new page where you can accept to trust yourself as a developer.
So, now you can use your device to test your application for Xcode.
So, if you want to add your iPad, the process is exactly the same. Just put then screenshot for future reference.
First, go the the Privacy & Settings and enable the Developer Model after the registration with your macOS computer.
Now, if you try to deploy and run the dummy project, you get the error on your macOS computer and also on your iPad. You see the error in the screenshot below.
So, go to General and then VPN & Device Management and click on the Apple Development under Developer App.
Finally, you can click on Trust Apple Deverloper.
After clicking on that, you have to Trust the developer. For this reason, you see a popup window that asks you explicitly to click on Trust.
Finally, your device is ready to receive deployment from your macOS machine. If you want to deploy your application from Visual Studio to a real device, you have to pay Apple.
Configure Visual Studio
If you want to deploy from your Visual Studio to your physical devices, you have to be registered as a developer on the Apple Store Connect.
In case you don’t have a registration with the Apple Store Connect, you will receive this error:
Error Automatic Provisioning is enabled but no Development Team was selected. Please select a team or switch to Manual Provisioning from the iOS Bundle Signing page.Visual Studio
If you don’t pay Apple, you will only be able to deploy from Visual Studio to a iOS Simulator.
Generate keys from Apple
To generate keys, you must have an Admin account in App Store Connect. You may generate multiple API keys with any roles you choose.
To generate an API key to use with the App Store Connect API, log in to App Store Connect.
- 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 appears on the page.
Download and Store the Private Key
Once you’ve generated your API key, you are given the opportunity to download the private half of the key. The private key is available for download a single time.
- Log in to App Store Connect.
- Select Users and Access, and then select the API Keys tab.
- Click “Download API Key” link next to the new API key.
The download link appears only if the private key has not yet been downloaded. Apple does not keep a copy of the private key.
Add Android SDK
When Visual Studio starts to compile the project, an alert comes up because we have to accept the Android licence and install the version 31 of the Android API. So, accept the licence first.
After that, choose from the list of Platforms at least the API Level 31 as Visual Studio required.
After the selection, you have to accept again the licence for the new platforms.
Now, compile again the project. It takes a while…
Half an hour later, Visual Studio installed all the dependencies for the project.
Now, in the Visual Studio toolbar, use the Debug Target drop down to select Android Emulators and then the Android Emulator entry
In the toolbar press the Android Emulator button
Accept again the licences 🤐and then in the User Account Control dialog, press the Yes button
Then, accept again the Android licences (I’m already bored to create application with MAUI) and then in the Visual Studio toolbar, press the Android Emulator button
Now, Visual Studio will start to create a default Android emulator. In the User Account Control dialog, press the Yes button
In the New Device window, press the Create button
Wait for Visual Studio to download, unzip, and create an Android emulator. After that, Close the Android Device Manager window
In the Visual Studio toolbar, press the Pixel 5 – API 30 (Android 11.0 – API 30) button to build and run the app
Visual Studio will start the Android emulator, build the app, and deploy the app to the emulator. After 10 minutes, the app is on the emulator, and I can click the button!
In conclusion, after all of it, we can finally deploy on a simulator, emulator or real device our application. If there is anything else I missed, please send me a message via the Forum.
Based on what we have done, I’m going to create a new project for display advertisements in our applications and monetize with apps.
But this is the subject of the next post! Happy coding!