RangerRick
RangerRick

Reputation: 296

How to target specific frameworks when building .Net MAUI app?

I am new to .Net Maui. I have a lot of experience with Xamarin. I am using Rider for MacOS.

I am attempting to build a .Net MAUI Application for iOS and Android. I've successfully created a .Net Maui template (from Rider). Since Android is easier to build and deploy, I want to start there. However, when I created a new MAUI template and clicked "Run" in my IDE, I got a bunch of iOS and MacOS specific errors. Through much weeping and gnashing of teeth, I discovered that this was because my project's TargetFrameworks were set in the MyApp.csproj file like so:

<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>

I discovered that removing all target frameworks (below) except for net6.0-android resulted in the successful build and deployment of the MAUI app! Hooray!

<TargetFramework>net6.0-android</TargetFramework>

The problem with this solution is that I now can't build my MAUI app for iOS or MacOS. Is there a way to say:

1. If the user is trying to build an android app => TargetFramework = net6.0-android
2. If the user is trying to build an iOS app => TargetFramework = net6.0-ios
3. etc.

In other words: "I'm only trying to build Android right now. Don't worry about compiling things for any other platform / framework. I may want to build for a different platform / framework later! Just not right now"

Upvotes: 4

Views: 9291

Answers (1)

ToolmakerSteve
ToolmakerSteve

Reputation: 21253

You can almost get this effect (tested in VS 2022 Preview, on Windows PC):

  • Rt-click project / properties / Application.
  • Notice sections "iOS Targets", "Android Targets", "Windows Targets".
  • Each has a checkbox "Enable targeting of the ... platform". Use those.

This doesn't automatically change as you change target. But its easier than editing .csproj.

Upvotes: 1

Related Questions