.Net MAUI is a cross-platform framework for creating native mobile and desktop apps with c# and XAML. You can refer to my previous article for getting started with the Dotnet MAUI application. Building iOS application in Windows machine Using Visual Studio 2022, Will do following two approaches for debugging and build the iOS application.
  1. Remote Host (Required Mac)
  2. Xamarin Hot Restart (Without Mac)
In this article, I will show Pair to Mac M1 Chip from windows machine for MAUI iOS app using Visual Studio 2022 preview. I am going to show a POC app with Visual Studio2022 preview, you can also use the same steps in Visual Studio 2019 or 2022++ version.

Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

Mac M1 Chip Setup

Mac Setup is ready here with the following configuration, Upgraded macOS Monterey 12.0.1 version in the Apple M1 Pro Macbook.

Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview


The Mac system installed Xcode 13.3 ++ and Visual Studio for mac. You have to open Xcode manually after installing so that it can add any additional components.

Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

You must follow the below steps to enable Remote Host.
  1. Select the “System preferences
  2. Click on the Sharing pane.

Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

You must configure remote login and follow the below configuration
  1. Remote login Set as “ON
  2. Configured to allow access for all users.
  3. If prompted, configure the macOS firewall.
Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

You must connect your Mac with the same Wi-Fi network or wired network.

Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

You can click on the Computer icon to connect mac machine or select Tools > iOS > Pair to Mac.

Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

If it is on the same network as the windows machine, the Mac should now be discoverable by Visual studio, if the Mac is still not discoverable, try manually adding a Mac.

Provide Mac name or Mac IP address which is in the remote Login preference on the Macbook.

Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

At the prompt, enter your username and password for that machine after the IP address is entered in the above screen.

Pair to Mac uses these credentials to create a new SSH connection to the Mac, Remote Host will take care of automatically checking the connection and verifying the Mac machine setup, if any mismatch you will get the error popup and ask you resolve and retry.


Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview


When Visual Studio is connected to a Mac, that Mac's item in the Pair to Mac dialog displays an icon indicating that it is currently connected

Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

You will be able to see the below screen automatically. All iOS simulators are loaded after the mac connected successfully and also able to see the computer icon indicated with a green icon.

Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

If you have any issue verify in iOS setting a windows machine, On Visual Studio > Tools > options > Select the iOS setting.
  1. Verify the XCode path, make sure Xcode installed in the application folder from Mac machine
  2. Remote Simulation should be on, otherwise, Simulator won’t be displayed on windows machine


Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

Remote iOS Simulator shows up as a black screen

Completely unable to use the iOS Simulator for Windows 10, only happening when using an M1-based Mac. When using an Intel-based Mac, we can successfully use the iOS simulator.

A fix for this issue has been Microsoft implemented and is being prepared for release. Microsoft will update to all once it becomes available for download.

Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

There is a workaround to force the simulator to load on the Mac M1, which works, but is certainly not a great solution and isn’t viable for many.

You can go to Tools->Options->Xamarin->iOS Settings and uncheck ‘Remote Simulator to Windows’.

Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

The MAUI application is ready to show on the iOS simulator from Mac M1 chip.


Xamarin MAUI: Pair to Mac M1 chip from Windows machine for iOS development using Visual Studio 2022 Preview

Summary

This article showed steps how to use Pair to Mac M1 chip to connect Visual Studio 2022 preview to a Mac build host, enabling Visual Studio 2022 preview developers to build iOS applications with MAUI


.Net MAUI is a cross-platform framework for creating native mobile and desktop app with c# and Xaml. In my previous article, we did warn welcome to Dotnet MAUI and shared information about the History of Xamarin.

MAUI as everybody already knows is a name for a new upgrade solution as a Multi-platform APP UI framework for building native cross-platform apps with .Net for android, iOS, macOS, and Windows. I am going to show how to create, build and debug the First MAUI application using Visual Studio 2022.

NET MAUI is the .NET Multi-platform App UI, a framework for

MAUI and other third-party framework teams started working on support for upgrading the app and old NuGet package to MAUI. MAUI will also provide you support for building the apps in different modern patterns and frameworks MVVM, MVU and RxUI.

.NET MAUI IDE


Microsoft provided 3 fantastic IDE Tools to create and develop apps with .NET MAUI and the happy news is MAUI is an open source.
  1. Visual Studio
  2. Visual Studio for Mac
  3. Visual Studio Code

Visual Studio 2022

On Windows or Mac machines you can use Visual Studio Code or Visual Studio/ VS for Mac for development. You will need the visual studio 2022 17.1.0 preview version. Microsoft released Visual studio 2022 version 17.0 in Nov month, but MUAI is still in preview so you can start to install visual studio 2022 17.1.0 preview version to create your first MUAI application.

Build your first .NET MAUI app

After installation success, Open the Visual Studio IDE

What .NET MAUI Means for Xamarin Developers

In this sample demo application, I am  going to show Android, iOS, and Windows app using MAUI, so Get started with “Create New Project”

What is .NET MAUI, and How Does it Differ from Xamarin?

On the new Project template, select project type as an” MAUI” and you will all the MAUI preview template, if you are not finding the MAUI template means, you have not installed the latest preview version so make sure you have installed the latest preview version 17.1 ++.

Microsoft Replaces Xamarin Toolkits with New .NET MAUI

In the Configure your new project window, name your project, choose your project location where you need to save, and click the Create button

The future of Xamarin: .NET MAUI

MAUI Solutions Structure

After clicking on Create, MAUI solutions default template loaded with all the related MAUI NuGet packages. There is a single project with different platform folders and resources.

Creating first .Net MAUI project

MainPage.XAML

The main page, whichever design, will support all other platforms as well, and also Main Page XAML build action modified in MAUI app.

Main Page.Xaml build action modified with MAUIXAML, make sure Xaml Build action is correct.

Right click on the XAML page >>Properties>>BuildAction of XAML Page to MauiXaml.

Creating new .NET 6 MAUI project

.NET Generic Host


The Worker Service templates, create a .NET Generic Host, HostBuilder. The Generic Host can be used with other types of .NET applications, such as Console apps.

Maui Program class enables apps to be initialized from a single location, and provides the ability to configure fonts, services, and third-party libraries.

iOS, Android, windows, and all the platform entry point calls a CreateMauiApp method of the static MauiProgram class that creates and returns a MauiApp, while lunch the application

.NET MAUI: How MAUI Will it impact on Xamarin Native applications?

Application Class

The App class derives from the Application class

Workload Repair failed: `dotnet workload repair - MAUI



Resources

The resources are a good improvement in MAUI. The AppIcon, image and font folder will be available under the MAUI project and it is just a single SVG, Looks like Maui will just automatically take care of generating all the different icon sizes for different devices.


How do I determine where the error is when I check MAUI compatibility with maui-check?How do I determine where the error is when I check MAUI compatibility with maui-check?

Run IOS App

Building MAUI iOS applications requires access to Apple's build tools, which only run on a Mac. Because of this, Visual Studio 2022 must connect to a network-accessible Mac to build iOS applications.

You must install the Xcode 13.1++ version on the Mac machine before connecting Visual Studio 2022 to the Windows machine.

Windows Configuration 

  1. Connect same wifi network
  2. Download and install Visual Studio 2022 with MAUI

Mac Configuration

  1. Connect same wifi network
  2. Install Xcode 13.1 ++
  3. On Network preference > switch on Remote login
Pair to Mac machine from windows

Pair to Mac for Xamarin.iOS Development

Program.cs

Program class file is the main entry file on IOS app and executes the main method of the application, here you can define your custom app delegate file and other configuration files

Appdelegate.cs

Each platform will call MauiProgram static class for initialize. On iOS will call as below

You can select iOS simulator and device and click Run icon for executing the application



The out as like below



Run Android App

The android application, MainApplication.cs will execute first, it will call the MauiProgram static class initially as like below
 
You can select android simulator or device as below, press F5 to run the application
 


The output like below



Run Windows App


The Windows application executes  App.xaml.cs file first, it will call the MauiProgram static class initially as like below

Select the device and run the Application



MAUI Windows device

Demo Video

I have shared a recorded demo video with two versions, English and Tamil. It will help you to understand more about creating, building, and debuging the First MAUI application.

English Demo Video



Tamil Demo Video 



Hope this article is very useful for you, If you have any questions/ feedback/ issues, please write in the comment box

An Azure key vault is a cloud service for securely storing and accessing secrets. A secret is anything that you want to tightly control access to such as API Key and Subscription, Password, Secure content, Connection string, and certification.

The developer no need to write secure content in UI Application, take as an example previously, we storing our database connecting string to in the UI application as a plain text or creating custom encryption algorithm for encrypting and decrypt the connection, now Microsoft provided a fantastic feature for store and retrieve the secure content in Azure key vault and azure will take care for your safety about content.

I am sharing a quick experience that you may also experience same in your working environment, on Prod environment database is more secure and live, but always developer can able to find the prod database connection string from config file and using same connection string developer can able to login database, edit the value, if developer update any value wrongly, that is become a bigger issue and also admin trying to change the password every frequent also application should have to do redeployment. Here, to avoid this issue, the application owners can use the azure Key vault to a prod database.

Azure portal: Create a key vault

A good practice is to create a separate vault for each deployment environment of each of your applications, such as development, test, and production. 

In this article, we will learn more about how to create an Azure key vault using the Azure portal. Once you have created a key vault, you can enable the “Azure monitor Log” to monitor the key vault.

Create Azure Key Vault

Step 1: Navigate to Azure Portal and create / login to the portal

Step 2: create a new azure key vault as shown below

Step 3: Navigate create new Resource > Search “Key Vault”, you will get the following screen and click on create.

Quickstart - Create an Azure Key Vault with the Azure portal

After clicking on the Create new button, you will get the following screen which you can provide info about your key vault
  1. Select Subscription and Resource group.
  2. Provide key vault name, Vault name must only contain alphanumeric characters and dashes and cannot start with a number.
  3. Select the region, which is nearest to your deployment zone.
  4. Pricing tier: Key Vault is designed to store configuration secrets for server apps. It's not intended for storing data belonging to your app's users, This will reflect the cost model. Azure Key Vault service is offered in two service tiers: standard and premium, pricing will refer below table by the West Us region and Indian currency. The best-recommended way, please go and check-inway, please go and check on Microsoft official website for exact current pricing based on your region

Key Vault pricing

You have to fill in the details as shown screen shot below

Manage Key Vault in Azure Stack Hub using the portal - Azure

After clicking on the Review + create a button, the Azure portal will validate the information and will give the confirmation with the review screen

Azure Key Vault Tutorial | Secure secrets, keys and certificates easily

Click on the Creation option and wait for a few min for deployment

Azure Key Vault Reviews 2021: Details, Pricing, & Features | G2

Click to go to Resource and be able to find 3 types of Azure Key Vault (KV) stores: 
  1. secrets
  2.  keys 
  3. certificates (certs).

Azure portal: Create a key vault

Secrets 

 Provides secure storage of secrets, such as DB connection strings, account keys, or passwords for PFX (private key files). The secret is a name-value pair of strings. Secret names must be 1-127 characters long, contain only alphanumeric characters and dashes, and must be unique within a vault. A secret value can be any UTF-8 string up to 25 KB in size.
  1. Upload options have two different types 1. Manual 2. Certificate.
  2. Name: Provide a valid secret name. Secret names can only contain alphanumeric characters and dashes.
  3. Value: Provide the single line value, the Azure Portal currently only supports single-line secret values, use Azure PowerShell to set multi-line values.

Azure portal: Create a key vault

(Cryptographic) Keys 

keys represented as JWK (JSON Web Key). Supports multiple key types and algorithms, and enables the use of Hardware Security Modules (HSM) for high-value keys.

There are 3 options to create the key
  1. Generate - Key type is RSA and EC, Select RSA and EC size and provide activate expiration date
  2. Import – Select your key to upload, Key type is RSA and provide activate expiration date
  3. Restore Backup -Select existing key to upload

Azure portal: Create a key vault=

Certificates 

Certificates are a managed X.509 certificate, which is built on top of keys and secrets and adds an automated renewal feature/auto-rollover. When a Key Vault certificate is created, an addressable key and secret are also created with the same name. The Key Vault key allows key operations and the Key Vault secret allows retrieval of the certificate value as a secret. A Key Vault certificate also contains public x509 certificate metadata.

Azure portal: Create a key vault

If you try to browse on secrets, key, and certificate key identifiers from the azure portal, you will get an unauthorized response because Keyvault is not public internet and is controlled through Active Directory.

Azure portal: Create a key vault

What next?

In this article, You created a new different azure key vault using the Azure portal. Will share in the next article about Key Vault integrate with xamarin mobile applications.

Featured Post

Improving C# Performance by Using AsSpan and Avoiding Substring

During development and everyday use, Substring is often the go-to choice for string manipulation. However, there are cases where Substring c...

MSDEVBUILD - English Channel

MSDEVBUILD - Tamil Channel

Popular Posts