.NET MAUI › Project Structure & App Startup
How does multi-targeting work in the MAUI .csproj?
IntermediateAnswer
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.