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:
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?
Maui on VS side uses a single project that compiles for all platforms upon build
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.
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 . 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 ;).