Skip to content

Samples for .NET Multi-Platform App UI (.NET MAUI)

License

Notifications You must be signed in to change notification settings

121969768/maui-samples

Repository files navigation

.NET 6.0.0 Mobile Samples

This is an early preview of Mobile (iOS/Android) in .NET 6 not for production use. Expect breaking changes as this is still in development for .NET 6.

If you are looking for the absolute newest download links see the develop branch.

This repo requires a specific build of .NET 6:

You will also need to install builds of the iOS and Android workloads:

Android:

iOS:

These builds are newer than .NET 6 Preview 1 and require Xcode 12.4. Use downloads from .NET 6 Preview 1 for Xcode 12.3:

Mac Catalyst:

NOTE: newer builds of .NET may work, but your mileage may vary. The workload installers enable a feature flag file via sdk/6.0.100-preview.1.21103.13/EnableWorkloadResolver.sentinel, which would need to be created manually for other .NET 6 versions. You can find the full list of builds at the dotnet/installer repo.

Projects:

  • HelloMaui - a multi-targeted .NET MAUI Single Project for iOS and Android
  • HelloAndroid - a native Android application
  • HelloiOS - a native iOS application
  • HelloMacCatalyst - a native Mac Catalyst application

Android

Prerequisites:

  • You will need the Android SDK installed as well as Android SDK Platform 30. Simplest way to get this is to install the current Xamarin workload and go to Tools > Android > Android SDK Manager from within Visual Studio.

For example, to build the Android project:

dotnet build HelloAndroid

You can launch the Android project to an attached emulator or device via:

dotnet build HelloAndroid -t:Run

iOS

Prerequisites:

  • Xcode 12.4. Earlier versions won't work.

To build the iOS project:

dotnet build HelloiOS

To launch the iOS project on a simulator:

dotnet build HelloiOS -t:Run

.NET MAUI

To launch the .NET MAUI project, you will need to specify a $(TargetFramework) via the -f switch:

dotnet build HelloMaui -t:Run -f net6.0-android
dotnet build HelloMaui -t:Run -f net6.0-ios

Using IDEs

Currently, you can use Visual Studio 2019 16.9 Preview 4 on Windows (with the Xamarin workload) with a few manual steps.

Open an Administrator command prompt to enable the EnableWorkloadResolver.sentinel feature flag:

> cd "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver"
> echo > EnableWorkloadResolver.sentinel

Or in an Administrator powershell prompt:

> cd "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\SdkResolvers\Microsoft.DotNet.MSBuildSdkResolver"
> '' > EnableWorkloadResolver.sentinel

NOTE: your path to Visual Studio may vary, depending on where you selected to install it. Preview is the default folder for Visual Studio Preview versions.

This command creates an empty file that enables .NET workload support. Restart Visual Studio after making this change.

Visual Studio for Mac support will be coming in a future release.

iOS from Visual Studio

To build and debug .NET 6 iOS applications from Visual Studio 2019 you must manually intall the .NET 6 SDK and iOS workloads on both Windows and macOS (Mac build host).

If while connecting Visual Studio to your Mac through XMA you are prompted to install a different version of the SDK, you can ignore that since it refers to the legacy one.

Note: currently only the iOS simulator is supported.

Mac Catalyst from Visual Studio for Mac

Running and debugging apps from Visual Studio for Mac does not work yet.

Known Issues

  • There are no project property pages available for both iOS and Android
  • Editors (i.e. Manifest editor, Entitlements editor, etc.) will fail to open, so as a workaround please open those files with the XML editor.

Android from VSCode

Support has been added to allow debugging of Android based apps in VSCode. Open the net6-mobile-samples.code-workspace in VSCode.

> code net6-mobile-samples.code-workspace

To build your application use open the Command Pallette and select Run Build Task. Select Build and then the Target you want to run. Available targets are:

  • Build : Builds the Project.
  • Install : Installs the Application on a Device or Emulator.
  • Clean : Clean the Project.

You can then select the Project and then the Configuration (Debug or Release) you want to Build.

To Debug goto the Run Tab and make sure Debug is selected. Click the Run button. You will be prompted on which project you wish to run, then asked which TargetFramework you want to target. For now only net6.0-android is supported. You will then be asked if you want to attach the debugger. Finally you will be asked which configuration you wish to use Debug or Release. After this the application should deploy and run, breakpoints should behave as normal.

Note: You will need to build your application at least once via Run Build Task. This is to that NuGet packages are restored correctly. This should not be required once dotnet#15485 is resolved.

Workarounds

These are notes for things we had to workaround for these samples to work.

NuGet

Currently, NuGet is not able to restore existing Xamarin.Android/iOS packages for a .NET 6 project. We tried $(AssetTargetFallback), however, this option does not work in combination with transitive dependencies. The Xamarin.AndroidX.* set of NuGet packages has a complex dependency tree.

For now we added workarounds in xamarin-android, see xamarin-android#4663.

About

Samples for .NET Multi-Platform App UI (.NET MAUI)

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.1%
  • Other 0.9%