Skip to content

Instantly share code, notes, and snippets.

@khalidabuhakmeh
Last active January 4, 2024 09:27
Show Gist options
  • Save khalidabuhakmeh/ce69f88451ef5e64f79053a806006cab to your computer and use it in GitHub Desktop.
Save khalidabuhakmeh/ce69f88451ef5e64f79053a806006cab to your computer and use it in GitHub Desktop.
Installing MAUI with .NET 7 for non-VS Users on macOS

Installing MAUI with .NET 7 for non-VS Users

Clear NuGet Cache

Before continuting to the next step, let's clear some nuget caches that might get in the way.

dotnet nuget locals all --clear

This should also free up GIGABYTES of disk space.

Fresh .NET Install

This step will require you to delete all your previous .NET installations. Trust me, it's better this way. If you're not sure where your .NET installation folder is on macOS, then you can run the following command in a terminal.

which dotnet

The output is likely going to be /usr/local/share/dotnet/dotnet. You'll want to run the following command to delete dotnet from your instance.

sudo rm -rf /usr/local/share/dotnet

Next, head to https://dot.net and download .NET 7 and if you need it for other projects, remember to download the other SDKs as well.

Installing MAUI

⚠️ Important Be sure you're running the 7.0.100-rc.2 SDK. Workloads install to the SDK version band you are using.

Run the following commands from a terminal. Be sure you're using the .NET 7 SDK by running dotnet --version. If you see anything other than .NET 7 you probably have a global.json file somewhere forcing the SDK version.

sudo dotnet workload install maui
sudo dotnet workload install maui-android maui-ios maui-maccatalyst
sudo dotnet workload install ios android maccatalyst

Running dotnet workload list will give you the following results.

dotnet workload list

Installed Workload Id      Manifest Version                         Installation Source
---------------------------------------------------------------------------------------
maui-maccatalyst           7.0.0-rc.2.6866/7.0.100-rc.2             SDK 7.0.100-rc.2
maui-ios                   7.0.0-rc.2.6866/7.0.100-rc.2             SDK 7.0.100-rc.2
maui-android               7.0.0-rc.2.6866/7.0.100-rc.2             SDK 7.0.100-rc.2
ios                        16.0.1271-rc.2-xcode14/7.0.100-rc.2      SDK 7.0.100-rc.2
maccatalyst                15.4.1186-rc.2/7.0.100-rc.2              SDK 7.0.100-rc.2
android                    33.0.0-rc.2.202/7.0.100-rc.2             SDK 7.0.100-rc.2

Use `dotnet workload search` to find additional workloads to install.

Installing Xamarin.iOS

You'll need to install the Xamarin-macios package found on this GitHub repository. https://github.com/xamarin/xamarin-macios/blob/main/DOWNLOADS.md.

🗒️ Note Be sure the package version 16.0.0.x or higher

Install XCode 14 and Android SDKs

You'll need XCode 14 installed and the Android SDKs 33+. If you're using JetBrains Rider you can use the environment tools to manage these settings.

Creating a new MAUI Project

You'll want to create a new MAUI Hello World app.

dotnet new maui -o HelloMaui
cd HelloMaui
dotnet restore
dotnet build

If everything went well, then you should have a functioning MAUI app. Try running the following command.

dotnet build -t:Run -f net7.0-maccatalyst

You should see a MAUI-powered macOS app running.

Troubleshooting

  1. If you're getting strange errors, double check your .csproj file. If TargetFrameworks isn't 7.0 then you likely used an old template. Clear your nuget cache and reinstall .NET.
  2. You need devices for Android and iOS. Be sure you have the latest SDKs for both.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment