Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add MAUI support #85

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

add MAUI support #85

wants to merge 8 commits into from

Conversation

chrfin
Copy link

@chrfin chrfin commented Jan 9, 2022

Proposed fix for #78 

This is an "as is" port using the exact same files via links compiled against the new TFMs. I only had to make some minor changes to the original files which should not change anything in the original TFMs.

@chrfin chrfin mentioned this pull request Jan 9, 2022
Copy link
Contributor

@maxkoshevoi maxkoshevoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There're lot's of CA1416 warnings for maccatalyst and iOS targets.
They might cause some runtime crashes

<PropertyGroup>
<TargetFrameworks>net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows')) and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks>
<UseMaui>true</UseMaui>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed (only adds unnecessary dependencies)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What part is not needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UseMaui. You can remove it, and everything would still compile

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, AFAIK without that the UWP/WinSDK is missing? I will try...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, it compiled for me when I removed UseMaui. Maybe needed to do rebuild or something for it to fail.

Maybe that's why current MAUI template also has this in it's project file:

<ItemGroup Condition="$(TargetFramework.Contains('-windows'))">
	<!-- Required - WinUI does not yet have buildTransitive for everything -->
	<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
	<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.0.30" />
</ItemGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
	<OutputType>WinExe</OutputType>
	<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, interesting - will try again on my side (incl. iOS tests) and report back...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, any news on that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry - had no time lately 😑
But it's still on my list 🙈

Calendars/Calendars.Plugin/CrossCalendars.cs Outdated Show resolved Hide resolved
@chrfin
Copy link
Author

chrfin commented Jan 10, 2022

I had some problems with my iOS test-system and did not test this build there yet - will do that ASAP and report back...

Calendars.nuspec Outdated Show resolved Hide resolved
@@ -2,26 +2,30 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.8.1">
<id>CClarke.Plugin.Calendars</id>
<version>1.1.0</version>
<version>1.2.0-preview11</version>
Copy link
Owner

@TheAlmightyBob TheAlmightyBob Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you would think it's that easy, but I think AppVeyor will overwrite this... I'll have to look into that again if going this route

(but why the 11?) - nevermind, I see the note about MAUI Preview 11, makes sense now

@@ -456,7 +457,7 @@ public async Task<bool> DeleteCalendarAsync(Calendar calendar)
throw new ArgumentException("Cannot delete calendar (probably because it's non-local)", nameof(calendar));
}

return await Task.Run(() => Delete(_calendarsUri, long.Parse(calendar.ExternalID))).ConfigureAwait(false);
return await Task.Run(() => Delete(_calendarsUri, long.Parse(calendar.ExternalID ?? String.Empty))).ConfigureAwait(false);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, possibly this should just return false if ExternalID is null rather than bother to call Delete.... but that can be out-of-scope for this PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a "dirty fix" for a more-or-less wrong nullable-detection, as it will never get to this place if the id would be null (except maybe some race-conditions). Because existing would be null in that case and it would return false a few lines above...

Maybe a check at the beginning of that method would make sense?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A check at the beginning makes sense to me. And yeah I understand and agree with your reasoning but the "dirty fix" still looks a bit odd to me

@TheAlmightyBob
Copy link
Owner

Well this "MAUI" project is new and interesting... you can have a single project that targets all the platforms now? (apologies for my ignorance, although I still skim the headlines I'm not as deep in the .NET world as I used to be)

Is that really a MAUI-specific thing though, or just a .NET 6 thing? I think it would be confusing if normal .NET 6 iOS/Android projects are dependent on a "MAUI" DLL.

@chrfin
Copy link
Author

chrfin commented Jan 11, 2022

I will look into dropping the "MAUI" part and be "plain net6.0" as soon as I find some time to also check the iOS build on my test-phone.

@TheAlmightyBob
Copy link
Owner

Your mention of "iOS tests" raises another question... are the Xamarin Unit Test apps even compatible with .NET 6? dotnet/android#5647 seems to suggest the answer will be "no"... says there's a "new" Xamarin.Legacy.NUnitLite (which despite the name appears to be Android-only) to use, but it's currently 0.0.1-alpha so dunno if it's usable yet.... for iOS, https://github.com/spouliot/Touch.Unit has had some updates, but is very lacking in documentation so not sure what the status or migration path there would be...

@maxkoshevoi
Copy link
Contributor

not sure what the status or migration path there would be

How about XHarness?
#78 (comment)

@maxkoshevoi
Copy link
Contributor

maxkoshevoi commented Jan 11, 2022

you can have a single project that targets all the platforms now
Is that really a MAUI-specific thing though, or just a .NET 6 thing?

Yes! That's one of the features. It's not MAUI specific.

  • Specifying multiple target frameworks (<TargetFrameworks> tag) has been a thing since .Net Core 2, I believe
  • Having code for multiple OSes in the single project could be done also from .Net Core 2 by using conditional compilation (like @chrfin did here), but starting from VS2022 we now also have <SingleProject> tag, that does that conditional include for us (doesn't do anything in our case though, since all files are explicitly included)

@TheAlmightyBob
Copy link
Owner

not sure what the status or migration path there would be

How about XHarness? #78 (comment)

Ah, I missed that previous comment. Interesting. It sounds potentially limiting in terms of development flow (e.g. being able to rerun/debug a single test?), but that could just be me misinterpreting the brief documentation. Worth looking into... but hopefully the existing tests can still work for now

Specifying multiple target frameworks ( tag) has been a think since .Net Core 2, I believe

Wow, how did I miss that. I just found https://montemagno.com/converting-xamarin-libraries-to-sdk-style-multi-targeted-projects/, which I see also talks about the nuspec thing that was confusing me...

starting from VS2022...

Hmmm.... that reminds me, the challenge of updating CI config will likely come up again for this. It might be wise for me to try to tackle that before this gets merged (though that shouldn't stop it from getting to a merge-ready state)... especially if it means needing to move off of AppCenter...

@maxkoshevoi
Copy link
Contributor

maxkoshevoi commented Jan 19, 2022

the challenge of updating CI config will likely come up again for thi

Example of MAUI CI: https://github.com/maxkoshevoi/NureTimetable/blob/maui/.github/workflows/build.yml
You'll just need to run dotnet workload install maui instead of dotnet workload install maui-android to build MAUI project

And here's CI for regular Xamarin app: https://github.com/maxkoshevoi/NureTimetable/blob/main/.github/workflows/build.yml
(also just builds Android, but should also work for Windows, to build iOS, I believe mac agent needs to be used)

@goatrodeosoftware
Copy link

goatrodeosoftware commented Apr 25, 2023

For what it's worth, I downloaded this branch and referenced it directly, and whereas I was getting the "This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation." error on iOS (I guess the NETSTANDARD1_0 check was getting activated?), everything works on maui android and iOS now. Thanks a ton!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants