Add Avalonia.Controls.Maui support to templates#35950
Conversation
|
Hey there @@drasticactions! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Hey there @drasticactions! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 35950Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 35950" |
kubaflo
left a comment
There was a problem hiding this comment.
PR #35950 — Add Avalonia.Controls.Maui support to templates
Verdict: NEEDS_CHANGES (confidence: high). Nice addition — the new --with-avalonia option is structurally well-wired through template.json symbols, dotnetcli.host.json, the csproj (desktop head + Avalonia.Controls.Maui package refs), and there's an integration test. But the generated project doesn't compile in the Avalonia-on case.
Blocking (inline)
- ❌
MauiProgram.cs:27—UseAvaloniaEmbedding<AvaloniaApp>()references an undefinedAvaloniaApp. On the mobile heads the embedding path needs an AvaloniaApplicationtype that the template never generates, so--with-avaloniaproduces a project that fails to build (CS0246). Generate theAvaloniaApptype as template content (or target an existing type). (3 models + code-confirmed.)
Suggestions (not blocking)
- Integration test coverage (
SimpleTemplateTest.cs):WithAvaloniaAddsHandlersAndDesktopHeadcurrently mostly asserts generated content rather than building the Avalonia-on project. A build assertion would have caught theAvaloniaAppissue above — consider compiling the generated project with the option enabled. (gemini) template.jsonversion default (~line 202): the11.0.0-preview.*floating range is reasonable for a preview-stage integration but pins consumers to whatever floats at restore time; consider a fixed version or document the intent. (opus-4.6)template.json:199parameterdataType— minor convention nit per gemini; worth a glance.
CI
Check Build/*Templates* integration legs once the AvaloniaApp issue is fixed — the template-generation tests are the relevant signal here.
Solid groundwork; the one real blocker is the missing AvaloniaApp in the generated output. Happy to re-review.
| #if !IOS && !MACCATALYST && !ANDROID && !WINDOWS | ||
| .UseAvaloniaApp(useSingleAppLifetime) | ||
| #else | ||
| .UseAvaloniaEmbedding<AvaloniaApp>() |
There was a problem hiding this comment.
The generated project won't compile with --with-avalonia on the mobile heads — AvaloniaApp is undefined. On iOS/MacCatalyst/Android/Windows (the #else branch here) the template emits .UseAvaloniaEmbedding<AvaloniaApp>(), but AvaloniaApp is never generated anywhere in the template output — git grep finds it only on this line. (UseMauiApp<App>() at line 21 works because the template does generate App.) So a user who runs the template with the Avalonia option gets a project that fails to build with CS0246: The type or namespace name 'AvaloniaApp' could not be found. Either generate an AvaloniaApp (the Avalonia Application subclass that UseAvaloniaEmbedding<T> expects) as part of the template content, or point the embedding at the type that actually exists. The desktop branch (.UseAvaloniaApp(useSingleAppLifetime), line 25) doesn't need a type arg, which is why only the mobile/embedding path is broken. (Consensus: gpt-5.5 + gemini flagged this as an error; opus-4.6 as a warning; confirmed by code.)
There was a problem hiding this comment.
That should be fixed with 5f14dc8
It's an MSBuild parameter setting thing where it's correctly setting the flags for those platforms in source, but not from the nuget props. Setting it directly for everything will work (It's a setting since you could have your own Avalonia head written, but since this is a template app, you won't have that yet).
Re-review PR #35950 — Add Avalonia.Controls.Maui to templates (new head
|
|
With the pinning of versions, I'm fine with it. I'm not sure what's the right way for us to handling bumping the templates for new versions and what the other dependencies do. I'm open to discussions on that. |
(I know it says "MAKE SURE THIS PR IS TARGETING MAIN" but since these packages only run in net11.0, I think it's right to target it there, since it shouldn't be in net10 builds, but we can always retarget it)
Description of Change
This PR adds the command
--with-avaloniato the templates, which addsAvalonia.Controls.Mauidesktop support the generated MAUI app.app.mp4
This updates the basic template so it
Avalonia.Controls.MauiandAvalonia.Controls.Maui.Desktopnugetsnet11.0TFM as a deployable platform.useSingleAppLifetimeis a parameter value that would get passed in from the Avalonia builder for which lifetime to use.UseAvaloniaAppis where the Avalonia handlers are registered. It's if-defed out for the existing MAUI platforms so they render with native controls by default, since we're still working in this repo to enable running these handlers on those platforms.UseAvaloniaEmbeddingis enabled for those platforms to allow for "Embedded" Avalonia Maui controls and handlers, which is our existing Avalonia Maui Hybrid platform and lets you intergrate native and drawn controls together, with the native controls being the default.This is our first run of getting a template change in, so we're keeping it simple.
maui-mobiletemplate for Desktop support. It doesn't changemaui-blazor, which we don't support. I can addmaui-multiplatformsupport if we want now, or that can be another PR, I don't have a preference.11.0.0-...) but, of course, we can't align onMauiVersion. I can pin to a version if that's best.