DEV Community

David Ortinau
David Ortinau

Posted on

Installing .NET MAUI on macOS

Visual Studio 2022 takes on a lot of the effort for setting up your cross-platform development environment. So what do you do when you don't have VS22? In this post I'll cover how you can still get your environment setup for .NET MAUI development.

Pre-requisites

Install .NET 6 with .NET MAUI

  1. Download and run the .NET 6 installer from dot.net.
  2. Open Terminal or your favorite command line app and check that you're ready to install .NET MAUI.


> dotnet --version


Enter fullscreen mode Exit fullscreen mode

Option A) Install .NET MAUI using workload install command:



> sudo dotnet workload install maui


Enter fullscreen mode Exit fullscreen mode

This command will get you the latest released version of .NET MAUI plus the platform SDKs for Android, iOS, macOS, and Windows.

Option B) Pass in additional parameters to the same command in order to get a specific branch build.



> sudo dotnet workload install maui --from-rollback-file https://aka.ms/dotnet/maui/preview.11.json --source https://aka.ms/dotnet6/nuget/index.json --source https://api.nuget.org/v3/index.json


Enter fullscreen mode Exit fullscreen mode

Your app will use the newest version available on your system. If you wish to pin your project to a specific version of .NET MAUI such as preview 11, add this to your ".csproj":



<MauiVersion>6.0.101-preview.11.2349</MauiVersion>


Enter fullscreen mode Exit fullscreen mode

These commands can be found in the contributor's development guide on dotnet/maui

That's it! You now have the building blocks to create, build, and run a .NET MAUI app. Let's do that.

New App

To create a new app run:



> dotnet new maui -n "MyMauiApp"


Enter fullscreen mode Exit fullscreen mode

CD into the "MyMauiApp" directory and run the app:



> dotnet build -t:Run -f net6.0-maccatalyst


Enter fullscreen mode Exit fullscreen mode

Xcode Devices and Simulators

This will restore the project dependencies, compile the app, and launch it. The -f parameter is the "target framework moniker". Options include:

  • net6.0-android
  • net6.0-ios
  • net6.0-maccatalyst

To run Windows on Windows you need Visual Studio 2022.

Targeting iOS

In order to target an iOS emulator, you need to provide the device id (UUID). Open Xcode and then go to Windows > Devices and Simulators. Right-click the simulator you want to use and copy the "Device Identifier".

app running on macOS

Now append the value to the parameter -p:_DeviceName=:v2:uuid=:



> dotnet build -t:Run -f net6.0-ios -p:_DeviceName=:v2:udid=02C556DA-64B8-440B-8F06-F8C56BB7CC22


Enter fullscreen mode Exit fullscreen mode

Targeting Android

Before building the Android app, start an emulator or connect to a device using adb connect. Then you can run:



> dotnet build -t:Run -f net6.0-android


Enter fullscreen mode Exit fullscreen mode

app running on Android

Troubleshooting tip: if you get an error indicating you need to set the JavaSdkDirectory in Visual Studio, try adding the following to a file "Directory.Build.props".



<Project>
<PropertyGroup>
<JavaSdkDirectory Condition="'$(JavaSdkDirectory)'=='' and '$(JAVA_HOME_8_X64)'!=''">$(JAVA_HOME_8_X64)</JavaSdkDirectory>
</PropertyGroup>
</Project>

Enter fullscreen mode Exit fullscreen mode




Conclusion

Now you are up and running with .NET MAUI for building Android, iOS, and macOS apps on macOS. This doesn't provide you with modern productivity features like C# and XAML hot reload. Those come standard with Visual Studio 2022 (and the upcoming Mac version), or you can navigate your way through configuring any number of other hot reload options available such as LiveSharp or Reloadify3000. Personally, I'll be using Comet which rides atop .NET MAUI and is built around hot reload.

Top comments (3)

Collapse
 
wcoder profile image
Yauheni Pakala • Edited

Thanks for the great article!

Might be helpful links for someone:

Sample native projects on GitHub


Also, you can see the list of available simulators via terminal command xcrun simctl:

xcrun simctl list
Enter fullscreen mode Exit fullscreen mode

Run on iPhone 11 for example:

dotnet build -t:Run -f net6.0-ios -p:_DeviceName=:v2:udid=$(xcrun simctl getenv "iPhone 11" SIMULATOR_UDID)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
boydtwa profile image
W Boyd Taylor

As a suggestion I would like to see an article for .Net MAUI where I could set up a Mac as a build server for my PC version of Visual Studio. There is an old article for Xamarin but to-date I haven't been able to make it work.

Collapse
 
pedro_remedios profile image
Pedro Remedios

"uuid" should be "udid" :) Other than that great article!