Proposal: Add support for XAML codegen in Visual Studio for UWP/WinUI 2 on Modern .NET
Proposal: Add support for XAML codegen in Visual Studio for UWP/WinUI 2 on Modern .NET
Summary
By Modern .NET we mean .NET without builtin WinRT interop support, so .NET 5+.
With recent C#/WinRT developement, Windows.UI.Xaml projections are now possible. Bring full XAML support to it for the full experience.
Rationale
The XAML codegen build task (Microsoft.Windows.UI.Xaml.Build.Tasks) hardcodes to retrieve WinRT API declarations from winmds, which cannot be directly referenced in Modern .NET.
So this proposal updates the official XAML compile build task to properly support Modern .NET, with this we can:
- Build System XAML island apps with Modern .NET
- Build UWP apps with Modern .NET, targeting UWP-only devices like the Xbox
Scope
| Capability | Priority |
|---|---|
| This proposal will allow developers to build WinUI 2 XAML apps with Modern .NET | Must |
Important Notes
It is verified that the XAML codegen works resonably well with Modern .NET if this limitation is somehow worked around. An example is provided at https://github.com/driver1998/ModernNetUAP.XamlCompiler, where it swaps C#/WinRT projections DLL references with winmds during XAML codegen (pass 1), and swaps those back after XAML codegen (pass 2).
A demo app is included at https://github.com/driver1998/NetCoreApp, yes this is an UWP, with AOT support too.
This works because the code we compile in pass 1 will never be executed, only reflected to get type metadata for pass 2.
But these kind of efforts are finicky. We can't have any library that uses WinRT types in projections referenced in a project that need XAML compile, as that will lead to type mismatch during pass 1.