.NET MAUI
Project Structure & App Startup
5 question(s)
What is the purpose of the Platforms folder?
Beginner
The Platforms folder holds platform-specific entry points and code: Android (MainActivity, MainApplication), iOS/MacCatalyst (AppDelegate, Program), and Windows (App.xaml). MAUI compiles only the relevant Platforms subfolder for each target framework, so you can write native code guarded by that platform without #if in most cases.
Real-world example
A developer requests a runtime permission by editing only Platforms/Android/MainActivity.cs, leaving shared code untouched.
Common follow-ups: What is MainActivity? | How does per-platform compilation work?
Single Project
Platform Integration
Multi-targeting
Where do you place images, fonts, and app icons in MAUI?
Beginner
Shared assets live in the Resources folder: Resources/Images, Resources/Fonts, Resources/AppIcon, and Resources/Splash. They are declared in the .csproj as MauiImage, MauiFont, MauiIcon, or MauiSplashScreen build actions, and MAUI generates correctly sized platform assets at build time from a single source (SVGs are resized without quality loss).
<ItemGroup>
<MauiIcon Include="Resources\AppIcon\appicon.svg" />
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" />
<MauiImage Include="Resources\Images\*" />
<MauiFont Include="Resources\Fonts\*" />
</ItemGroup>
Real-world example
A designer supplies one appicon.svg and MAUI emits every density-specific icon Android and iOS require automatically.
Common follow-ups: How are SVGs resized? | How do you reference a font in XAML?
Resources
App Icons
Fonts
How does multi-targeting work in the MAUI .csproj?
Intermediate
The <TargetFrameworks> property lists monikers like net8.0-android and net8.0-ios. MSBuild builds the project once per moniker. You can use MSBuild conditions and the Platforms folder filename convention (e.g., MyService.Android.cs) so files compile only for matching targets, avoiding scattered preprocessor directives.
<TargetFrameworks>net8.0-android;net8.0-ios</TargetFrameworks>
<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-android'">
<DefineConstants>$(DefineConstants);MY_ANDROID</DefineConstants>
</PropertyGroup>
Real-world example
A CI pipeline builds only the Android target on a Linux agent and the iOS target on a Mac agent from the same csproj.
Common follow-ups: What are partial classes used for here? | How do filename conventions target platforms?
Multi-targeting
Conditional Compilation
Platform Integration
How do the native entry points bootstrap a MAUI app on Android and iOS?
Intermediate
On Android, MainApplication overrides CreateMauiApp() to return MauiProgram.CreateMauiApp(), and MainActivity (a MauiAppCompatActivity) hosts it. On iOS/Mac Catalyst, AppDelegate (a MauiUIApplicationDelegate) does the same. These bridge the native app lifecycle to the shared MAUI host.
// Platforms/Android/MainApplication.cs
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership) { }
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
Real-world example
When adding a third-party SDK that needs Application.OnCreate, the developer hooks it in MainApplication before the base call.
Common follow-ups: What class does MainActivity inherit? | Where is CreateMauiApp defined?
App Lifecycle
MauiProgram
Platform Integration
How do you register and consume platform-specific implementations of a shared interface?
Advanced
Define the interface in shared code, implement it per platform using partial classes or the Platforms folder, and register it in DI. A common pattern is a partial class with a shared signature and platform-specific bodies compiled per target, or conditional registration in MauiProgram.
// Shared
public interface IDeviceInfoService { string GetId(); }
// Platforms/Android/DeviceInfoService.cs
partial class DeviceInfoService : IDeviceInfoService
{
public string GetId() => Android.OS.Build.Serial ?? "unknown";
}
// MauiProgram.cs
builder.Services.AddSingleton<IDeviceInfoService, DeviceInfoService>();
Real-world example
A team reads a hardware identifier differently on each OS but injects a single IDeviceInfoService everywhere in shared code.
Common follow-ups: How do partial classes multi-target? | Could you use conditional DI registration instead?
Dependency Injection
Multi-targeting
Platform Integration