.NET MAUI
platform optimization
app development
software compilation
cross-platform development

How can I remove the platforms I do not need to compile for in .net MAUI?

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

Introduction

A .NET MAUI single-project app uses multi-targeting, which means one project can build for several platforms by listing multiple target frameworks in the project file. If you no longer need some platforms, the correct place to remove them is the .csproj file, not the Platforms folder. In practice, you reduce the TargetFrameworks list to only the platforms you actually support.

The Setting That Controls Platform Compilation

In a MAUI project, the important property is TargetFrameworks. A typical project may start with several target framework monikers, often one for Android, one for iOS, one for Mac Catalyst, and one for Windows.

xml
1<Project Sdk="Microsoft.NET.Sdk">
2  <PropertyGroup>
3    <TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst;net9.0-windows10.0.19041.0</TargetFrameworks>
4    <UseMaui>true</UseMaui>
5    <SingleProject>true</SingleProject>
6  </PropertyGroup>
7</Project>

If you want only Android and iOS, remove the others from that property.

xml
1<Project Sdk="Microsoft.NET.Sdk">
2  <PropertyGroup>
3    <TargetFrameworks>net9.0-android;net9.0-ios</TargetFrameworks>
4    <UseMaui>true</UseMaui>
5    <SingleProject>true</SingleProject>
6  </PropertyGroup>
7</Project>

That is the main change. The SDK builds only the listed targets.

Use TargetFramework for a Single Platform

If the project should build for exactly one platform, you can use a single TargetFramework instead of TargetFrameworks.

xml
1<Project Sdk="Microsoft.NET.Sdk">
2  <PropertyGroup>
3    <TargetFramework>net9.0-android</TargetFramework>
4    <UseMaui>true</UseMaui>
5    <SingleProject>true</SingleProject>
6  </PropertyGroup>
7</Project>

This makes the intent very explicit and can simplify local development when the app is no longer truly cross-platform.

What You Usually Do Not Need to Remove

You generally do not need to delete the platform folders immediately. MAUI's single-project model uses multi-targeting so that platform-specific folders are included only for the matching target build. That means a Platforms/iOS folder is not compiled into an Android build just because the folder exists.

In other words:

  • removing the target framework stops that platform from being built
  • deleting the folder is optional cleanup
  • keeping the folder may still be useful if you plan to re-enable that platform later

This distinction matters because developers often remove source files first and leave the target framework untouched, which does not solve the build problem.

Conditional Platform Targets

Some MAUI project files use conditions so that a platform target is only added on a matching host operating system. For example, Windows targeting may be appended only when building on Windows.

xml
1<PropertyGroup>
2  <TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
3  <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
4</PropertyGroup>

If you no longer want Windows support, remove that conditional addition too. Otherwise the project may still target Windows on Windows machines.

Clean Up Platform-Specific References

After changing the target frameworks, review any platform-specific package references, runtime identifiers, or conditional item groups in the project file.

xml
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
  <PackageReference Include="Some.Android.Only.Package" Version="1.2.3" />
</ItemGroup>

If the platform is gone, the condition is harmless but unnecessary. Cleaning these sections makes the project easier to maintain.

You should also review CI pipelines and publish commands. A build server may still call dotnet publish -f net9.0-windows10.0.19041.0 even after the project file has changed.

Common Pitfalls

The most common mistake is deleting the Platforms folder for a platform but forgetting to remove its target framework. The build still targets that platform because TargetFrameworks is what actually drives compilation.

Another issue is removing a platform from one TargetFrameworks entry while leaving a conditional platform append elsewhere in the file. That can make the platform seem to "come back" on certain machines.

Developers also sometimes leave platform-specific package references, signing settings, or CI steps in place after removing a platform. That creates confusing build errors later.

Finally, if you only want to stop compiling a platform temporarily, do not over-clean the project. Removing the TFM is enough. You can keep the platform code in source control until the decision is permanent.

Summary

  • In .NET MAUI, platform compilation is controlled by TargetFrameworks or TargetFramework in the .csproj file.
  • Remove the platform TFM to stop building that platform.
  • Deleting the corresponding Platforms folder is optional cleanup, not the main fix.
  • Check for conditional target-framework entries and platform-specific references.
  • Update CI and publish commands so they match the reduced platform list.

Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms