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

Time:06-16

I only want to make a project for MacOS and Windows, no need for Android or iOS. I tried deleting the platforms from the folder called "Platforms" but they seem to regenerate each compile. Is there an official method for only targeting the platforms that are necessary? I looked at multiple project files, but there are Android and iOS tags scattered throughout.

Can someone please help me with this?

CodePudding user response:

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.
  • Related