Oxygene and MAUI

I am creating a library for .NET MAUI. Generally, everything works. However, the output files are not created in directories according to the MAUI convention, and compilation for individual platforms requires separate projects. But these are problems that can be bypassed. However, one problem seems unsolvable. The content of NuGet for individual platforms sometimes differs in API content. So far, Oxygen always uses the basic versions of the assembly for compilation. There is no option to force the use of platform-specific versions during compilation. In a C# project, this is done as follows:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
    <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>

So there is no option to specify the compilation platform, e.g., “net9.0-android”.

An example of code that cannot be compiled in Oxygen is:

#if ANDROID
  var dsp = Platform.CurrentActivity.WindowManager.DefaultDisplay;
#endif
{$IFDEF ANDROID}
   var dsp := Microsoft.Maui.Platform.CurrentActivity.WindowManager.DefaultDisplay;
{$ENDIF}

Hi.

Could you do me a favor and create a small sample project othat shows what you would like to work (and currenly fails), for me as a starting point to investigate?

Right now our projects have one “TargetFramework” (singular setting name); i am not sure how feasible it will be to support multiple TargetFrameworks in a single project/target, but i can investigate supporting -android et al sufixes for the target farmework, so something like this could work in a multi-target project (See Targets), woudl that be a good start?

I would also, ideally, use available() (See available()) for exposing what target you’re on, rather than/in addition to setting the define such as “#if android”.

I assume VC# builds 3-4 distinct versions of the project for your above scenario, right?

Update #if android & co will work in vNext.

I apologize for the late answer.

  1. Maui on VS side uses a single project that compiles for all platforms upon build
  2. The attached project can not be ported to Oxygene. Upon compilation, there is no way to ensure that proper platform libraries are referenced. Take a look at .csproj to see how the platforms are included.

MauiLibTest.zip (978 Bytes)

A simple conversion woudl be this:

MauiLibTest.elements.zip (1.3 KB)

though probably more work needs to be done; i’m not very fmailiar with Maui myself. Right now, this fails to buidl for Android (only) on

#if ANDROID
  using Android.Util; // E26 Unknown namespace "Android.Util" in uses list
#endif

i’m not sure where that namespace is supposed to come from, as – again – i’m not super familair with how Maui works.

After one fix i just made, it does properly resolve the Maui files from the right platform-specific folder, e.g.

./EBuild/Packages/NuGet/microsoft.maui.core/9.0.81/lib/net9.0-android35.0

But it doesn’t seem to get the Android namespaceform that; IDK if somehow something else needs to be “magically” pulled in for that. in the VC# project in VS, do you have a way to tell what .dll references the project gets and where Android.* might be coming from?

Tomorrow’s build will have that above-mentioned fix, as well as the fix for not saying “tizen” is an unknown platform…

Update: with my latest fixes, it now resolves the Android refs (what a mess Microsoft has made here once again :sob:. i had to reqrite large parts of the package resolving just because they chose to use a different folder structure for the Android pack that for any other NuGet packages…). however, i still do get the second error; it cant find the Platform type.

#if ANDROID
  using Android.Util; // fine now!
#endif

namespace MauiLibTest
{
    // All the code in this file is included in all platforms.
    public class Class1
    {
       public void Test() {
#if ANDROID
  var dsp = Platform.CurrentActivity.WindowManager.DefaultDisplay; // E509 Unknown identifier "Platform", did you mean "RemObjects.Elements.Cirrus.Platform"?
#endif
        }
    }
}

I did have to run dotnet workload install android to make the packages available locally (again - Why? idk. Isn’t the whole point of NuGet that it can et anyting remotely if needded? But oh well ;).