-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 globbing support for WinUI #3245
Comments
Should all globbing support live in the base SDK instead of living in the WindowsDesktop SDK? This may not work well if WPF's targets are deciding which markup compiler to invoke, but perhaps WPF's targets should not be deciding that anyway. IIRC WPF's targets are making local decisions for itself, based on In .NET Framework/old-style projects, when there was no use of microsoft/microsoft-ui-xaml#2498 (comment)
BTW, does WinUI have its own SDK yet? If it does, you can set up globbing etc. in that SDK's props/targets. OTOH, if the plan is never to have an SDK (for e.g., perhaps because WinUI is going to ship as a first-class component in .NET 5, and taking a clue from WindowsDesktop SDK's merger with the base SDK, has now decided not to invent a separate SDK for itself), then a better place to make these changes would be base Microsoft.NET.SDK. BTW, should Avalonia be rationalized here as well? AvaloniaUI/Avalonia#4102. Related: microsoft/microsoft-ui-xaml#1438 |
We aren't planning on having an MSBuild SDK. I don't know the timeframe, or if WinUI will be a first-class component of .NET. Definitely not in the .NET5 timeframe, but maybe for .NET6 when we can be an optional component. I think providing an error like you suggest for having As far as I'm concerned, Avalonia is welcome to piggy back on this as well. |
I think the targets for the different UI frameworks will need to coordinate at some level to avoid stepping on each other's toes. Do you think there will eventually be XAML island scenarios where you will want to have both WPF and WinUI xaml files in the same project? If so, then eventually I think you would want to be able to invoke both compilers, and determine which xaml files to pass to which compilers via a combination of convention and item metadata. For example, for a project that uses both, if the default is to interpret xaml files as WPF Pages, then you could have the following to select a file to be built with the WinUI compiler: <ItemGroup>
<Page Update="WinUIPage.xaml" XamlCompiler="WinUI" />
</ItemGroup> It might have been a better idea if early on WinUI switched to a different file extension (ie .winui). That ship has probably already sailed though. |
@marb2000 and @MikeHillberg are better equipped to answer that. |
It's a good scenario, but it's not in plan for WinUI3, which is the current focus. |
This is what's really going on: wpf/packaging/Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.props Lines 3 to 32 in 9ec4c6b
wpf/packaging/Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets Lines 84 to 151 in 9ec4c6b
Instead of enlightening WindowsDesktop SDK with more information about specific frameworks, why don't we consider making it less reliant on such knowledge in .NET 5 (including WPF) ? 😜 Bear with me - let me explain. Given that one-project will always map to one XAML dialect (like WPF, WinUI etc.), we don't need to annotate XAML With these changes, XAML files would always be globbed, and checked for duplicates etc. - and in Do I have it right so far @dsplaisted ? |
Our requirements are fairly simple, and I'm all for this being in the right place and done properly. If Just brainstorming...one convention we could adopt for WinUI and WPF in the same project is for WinUI pages have the
*ignore the fact that this isn't currently possible in MSBuild but it totally should be, you have to do something ugly like this:
The VS Wizard would need to know the WinUI Item is being added to a WPF project so that it adds the appropriate file name, but this would allow the .csproj to stay clean and xaml files to still have the xaml extension |
From the Avalonia perspective, I really like the XamlCompiler metadata if VS could use that to determine which XAML editor to load. That would solve one of the big issues Avalonia has when trying to work in VS. |
@stevenbrix if the same project is not going to have multiple XAML dialects (WinUI + WPF for e.g.), then where is the need to exclude WinUI XAML pages during globbing? A project can simply assume that all XAML pages belong to its own dialect (i.e, WPF project can assume everything is WPF, WinUI can assume that everything is WinUI etc.). It looks like globbing for XAML needs to work as a first-class construct. Beyond that, it's not clear whether any dialect-specific logic is needed at all. @jkoritzinsky Item-metadata hints to identify and load a different designer - iff one is registered - maybe interesting. /cc @diverdan92 |
@vatsan-madhavan and @dsplaisted so should this issue move to the https://github.com/dotnet/sdk repo then? |
If we are going to eventually support multiple XAML dialects in the same project, then we should try to make design decisions today with that in mind. For example, if eventually WinUI XAML files would use a .winui.xaml extension, then ideally we would already require or encourage that today. I can see the value of moving the XAML globs down into the .NET SDK, especially since WinUI doesn't currently have their own targets outside of a NuGet package. However, are the globs for WPF and WinUI actually the same? The WPF globs are not all that simple (see the snippets that @vatsan-madhavan linked). If we do move the globs into the .NET SDK, note that they would still only be active if UseWPF or UseWinUI was set to true. We don't want to suddenly change how we handle projects that don't use either UI framework but happen to have a .xaml file in the project folder. This also means that WinUI projects should explicitly set UseWinUI to true in the project file. If it were just set in targets from the WinUI NuGet package, then you would have different globs depending on whether the NuGet package was restored, which isn't a great experience in VS. |
@dsplaisted if we move XAML globbing to .NET.SDK (which is an idea I like), then we should make it opt-in generically using |
I would also add that it shouldn't do anything with |
Can this issue be moved to https://github.com/dotnet/sdk? Thanks. |
@ryalanms I was initially thinking this issue could just move, but we'll probably need a tracking issue to update the Windows SDK to w/e is done, so it makes sense to keep this around for that. @dsplaisted while I agree with your general sentiment, I just think that if we're able to make the globbing in the .NET SDK simple and generic enough, then we won't be putting ourselves into a corner. We don't support WinUI files in a WPF project, so if we decide they should adopt the I've filed this issue in the sdk repo: dotnet/sdk#12520 |
I have been globbing in WPF NetCore for so long now that I automatically started doing it in my Directory.Build.targets when I began writing WinUI code a few weeks ago without really knowing that it wasn't supported in WinUI. One sporadic issue that I see happen sometimes is that Visual Studio decides to add a "None Remove" to some of my files without re-adding them back in as a Page (I would rather it not touch them at all like you stated). Since it removes the file it goes missing from my solution and it causes quite the confusion when it happens.
I caused myself quite a headache today regarding ApplicationDefinition though. I renamed App.xaml, didn't assign a new ApplicationDefinition and was bouncing my head off of a null reference exception that is hit in the Microsoft.UI.Xaml.Markup.Compiler.interop.targets MarkupCompilePass2 target. There is no specific error message, just the "object reference not set to an instance of an object". This happened to me in the middle of a renaming refactor so I assumed the null ref was caused by some meta file, left-over binaries, manifest, something, anything..... until finally I gave up and reverted all of the changes to my code so I could start narrowing it down. Needless to say, I really punished myself just to rename that file for no good reason (My assembly name ended in App so rather than be forced to rename namespaces, the assembly and the folder containing the code, I figured it would be faster for my demo code to just rename App.xaml. Dear lord was I wrong). I really do not miss the days of Visual Studio messing with my project files and look forward to when it stops touching the ones for WinUI. The power of globbing and SDK style projects are one of my top 3 favorite things that happened to NetCore. |
Is there any workaround for now if I want to use both |
The WinUI team needs support for globbing support so that Visual Studio will not edit the .csproj whenever you add a .xaml file to the project. See this bug as a reference: microsoft/microsoft-ui-xaml#2498
In following the same pattern as WPF, we can add a
UseWinUI
property that will pull in theMicrosoft.NET.WindowsDesktop.Sdk
and enable the globbing support.If both
UseWinUI
andUseWpf
are true, then the SDK can assume all xaml files are for WPF. The WinUI nuget will respect the use ofUseWpf
and not invoke the winui xaml compiler if that is the case. If onlyUseWinUI
is true, then the SDK should not invoke PBT. Below is a table describing the different combinations and what should happen:True
True
True
False
False
True
False
False
The text was updated successfully, but these errors were encountered: