This page contains steps to build and run the .NET MAUI repository from source. If you are looking to build apps with .NET MAUI please head over to the .NET MAUI documentation to get started.
In most cases, when you have Visual Studio installed with the .NET workloads checked, these steps are not required.
- Install the latest .NET 6:
- Clear your nuget cache:
dotnet nuget locals all --clear
NOTE: this is going to contain the "stable" versions of the packages, so you will have to clear the NuGet cache when this feed changes and when .NET ships. The various
darc-pub-dotnet-*
feeds are temporary and are generated on various builds. These feeds my disappear and be replaced with new ones as new builds come out. Make sure to verify that you are on the latest here and clear the nuget cache if it changes:
You'll probably need to run these commands with elevated privileges:
Install the .NET MAUI workload using the versions from a particular branch:
For example, the "preview.13" branch:
dotnet workload install maui `
--from-rollback-file https://aka.ms/dotnet/maui/preview.13.json `
--source https://aka.ms/dotnet6/nuget/index.json `
--source https://api.nuget.org/v3/index.json
Or, the "main" branch:
dotnet workload install maui `
--from-rollback-file https://aka.ms/dotnet/maui/main.json `
--source https://aka.ms/dotnet6/nuget/index.json `
--source https://api.nuget.org/v3/index.json `
--source https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-6dd808ff-1/nuget/v3/index.json `
--source https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-emsdk-ee0a97a0/nuget/v3/index.json
If you are building maui yourself, then you probably want all the workloads:
dotnet workload install android ios maccatalyst tvos macos maui wasm-tools `
--from-rollback-file https://aka.ms/dotnet/maui/main.json `
--source https://aka.ms/dotnet6/nuget/index.json `
--source https://api.nuget.org/v3/index.json `
--source https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-runtime-6dd808ff-1/nuget/v3/index.json `
--source https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-emsdk-ee0a97a0/nuget/v3/index.json
NOTE: Zsh and Bash on macOS expect
\
instead for spanning commands over multiple lines. The examples above are formatted for windows/powershell
iOS and MacCatalyst will require Xcode 13.1 Stable. You can get this here.
Android API-31 (Android 12) is now the default in .NET 6.
This will build and launch Visual Studio using global workloads
dotnet tool restore
dotnet cake --target=VS-NET6 --workloads=global
You can run a Cake
target to bootstrap .NET 6 in bin\dotnet
and launch Visual Studio:
dotnet tool restore
dotnet cake --target=VS-NET6
NOTES:
- VS Mac is not yet supported.
- If the IDE doesn't show any Android devices try unloading and reloading the
Sample.Droid-net6
project.
You can also run commands individually:
# install local tools required to build (cake, pwsh, etc..)
dotnet tool restore
# Provision .NET 6 in bin\dotnet
dotnet build src\DotNet\DotNet.csproj
# Builds Maui MSBuild tasks
.\bin\dotnet\dotnet build Microsoft.Maui.BuildTasks.sln
# Builds the rest of Maui
.\bin\dotnet\dotnet build Microsoft.Maui.sln
# (Windows-only) to launch Visual Studio
dotnet cake --target=VS-DOGFOOD
To build & run .NET 6 sample apps, you will also need to use .\bin\dotnet\dotnet
or just dotnet
if you've installed the workloads globally:
.\bin\dotnet\dotnet build src\Controls\samples\Controls.Sample.Droid\Maui.Controls.Sample.Droid.csproj -t:Run
.\bin\dotnet\dotnet build src\Controls\samples\Controls.Sample.iOS\Maui.Controls.Sample.iOS.csproj -t:Run
Try out a "single project", you will need the -f
switch to choose the platform:
.\bin\dotnet\dotnet build src\Controls\samples\Controls.Sample.SingleProject\Maui.Controls.Sample.SingleProject.csproj -t:Run -f net6.0-android
.\bin\dotnet\dotnet build src\Controls\samples\Controls.Sample.SingleProject\Maui.Controls.Sample.SingleProject.csproj -t:Run -f net6.0-ios
To build and run Blazor Desktop samples, check out the Blazor Desktop wiki topic.
To build and run WinUI 3 support, please install the additional components mentioned on the Getting Started page and run:
dotnet tool restore
dotnet cake --target=VS-WINUI
To workaround a performance issue, all Resource.designer.cs
generation is disabled for class libraries in this repo.
If you need to add a new @(AndroidResource)
value to be used from C#
code in .NET MAUI:
-
Comment out the
<PropertyGroup>
inDirectory.Build.targets
that sets$(AndroidGenerateResourceDesigner)
and$(AndroidUseIntermediateDesignerFile)
tofalse
. -
Build .NET MAUI as you normally would. You will get compiler errors about duplicate fields, but
obj\Debug\net6.0-android\Resource.designer.cs
should now be generated. -
Open
obj\Debug\net6.0-android\Resource.designer.cs
, and find the field you need such as:
// aapt resource value: 0x7F010000
public static int foo = 2130771968;
-
Copy this field to the
Resource.designer.cs
checked into source control, such as:src\Controls\src\Core\Platform\Android\Resource.designer.cs
-
Restore the commented code in
Directory.Build.targets
.