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

Required Change
  • In your .csproj file, remove the targets for the platforms you aren’t building for, reducing it to the following:

    <TargetFrameworks>net6.0-maccatalyst</TargetFrameworks>
    <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
    
Optional Changes
  • In your .csproj file, remove the supported version information for the platforms you aren’t building for, reducing it to the following:

    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
    <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
    <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
    
  • Delete any subdirectories under the Platforms folder for the platforms you aren’t building for.

Caveats
  • You can only build for the Windows platform on a Windows machine.
  • You can only build for MacCatalyst from a Mac, or from a Windows machine that has been set up with Pair to Mac.

Leave a Comment