dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.98k stars 1.71k forks source link

Project file MauiXaml node inconsistent #7808

Open david-maw opened 2 years ago

david-maw commented 2 years ago

Description

When you create a new MAUI project it will contain AppShell.xaml and MainPage.xaml and corresponding.cs files. These will not be explicitly called out in the project file.

But when you add each new page it will cause the project file to be updated with a MauiXaml node in an ItemGroup. Deleting this new ItemGroup seems to make no practical difference and having it present makes for (trivial) conflicts when multiple changes to the same project need to be reconciled.

I'm not sure this rises to the level of a bug, but it is strange, do these nodes have a purpose, in which case why are there none for AppShell and MainPage?

Steps to Reproduce

  1. Create a file>New .NET MAUI App
  2. Add a page to it
  3. Look in the project file, you'll see only one MauiXaml node
    
    <ItemGroup>
    <MauiXaml Update="NewPage1.xaml">
    <Generator>MSBuild:Compile</Generator>
    </MauiXaml>
    </ItemGroup>

This node will be for the newly added page, there's not one for MainPage or AppShell (the other two XAML defined pages).

### Version with bug

6.0 (current)

### Last version that worked well

Unknown/Other

### Affected platforms

Windows

### Affected platform versions

Windows 10

### Did you find any workaround?

Just deleting the node if it causes a conflict seems to work fine.

### Relevant log output

_No response_
jonathanpeppers commented 1 year ago

I'm asking around about this internally. No guarantees, but I'd like to prevent item templates from editing the project file.

When this happens, it triggers some MSBuild targets to run in the Android workload, so it would help build performance to fix this -- and a weird bug, too.

david-maw commented 1 year ago

As far as I can tell they don't need to add MauiXml nodes, but I suppose it makes sense to do something to trigger a build when files are added to the project.

jonathanpeppers commented 1 year ago

@david-maw you don't actually need the %(Generator) at all, because MAUI uses Roslyn source generators for things like x:Name, you get valid intellisense without the need for a design-time build.

It looks like this can only be fixed by the Xamarin/MAUI extension in Visual Studio, by adding a provider like this for .xaml files:

https://devdiv.visualstudio.com/DevDiv/_git/WebTools?path=%2Fsrc%2FProjectSystem%2FWeb%2FProjectBuild%2FProjectItemGeneratorProvider.cs&_a=contents&version=GBmain

(sorry MS-private link)

jonathanpeppers commented 1 year ago

Tracked by: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1713708

XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.6.0 Preview 7.0. Repro on Windows 11 with below Project: MauiApp3.zip

This node will be for the newly added page, there's not one for MainPage or AppShell (the other two XAML defined pages). image

jonathanpeppers commented 1 year ago

@XamlTest this can only be fixed by a change in Visual Studio, as we tried to file on a private ticket here: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1713708

If others are wanting this change, please upvote or comment. Thanks!

XamlTest commented 1 year ago

@jonathanpeppers Thanks for the note, we're just doing a bulk re-triage of issues to see if latest changes affected the behavior at all.

mattleibow commented 10 months ago

I see the internal issue was marked as "Cut". Not sure if that was because it was fixed in another way, or we should re-open?

I am not near my Windows machine right now, but we will have to re-verify.

ghost commented 10 months ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

Zhanglirong-Winnie commented 9 months ago

Verified this issue with Visual Studio Enterprise 17.8.0 Preview 7.0. This issue also repro.

samhouts commented 7 months ago

Closing in favor of https://developercommunity.visualstudio.com/t/Project-file-MauiXaml-node-inconsistent/10507690