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
22.26k stars 1.76k forks source link

Removing .razor files via .csproj does not exclude them from the build process #25512

Open wjsimon opened 1 month ago

wjsimon commented 1 month ago

Description

If a .razor file is attempted to be removed from the build via the .csproj file it is still built.

This does not happen in other Blazor-based project templates, e.g. a Blazor WebAssembly Standalone App. Setting the "Build Action" property to "None" here will result in the .razor file not being included in the build. I did not test all available blazor-based templates for this.

The .csproj snippet in question: Image

Steps to Reproduce

  1. Create a new project in Visual Studio 2022, using the ".NET MAUI Blazor Hybrid App" project template including sample pages
  2. Set the "Build Action" property of the "Home.razor" file, automatically included in the project, to "None". This edits the .csproj file.
  3. Run the App

The app will succesfully build, and start showing the content of the excluded "Home.razor" file. I've tried this with .NET 8.0 as well as the .NET 9 Preview (9.0.0rc.2.24503.2)

Link to public reproduction project repository

No response

Version with bug

8.0.82 SR8.2

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

No response

Affected platforms

Android, Windows, I was not able test on other platforms

Affected platform versions

Android 14 - API 34, Windows SDK 10.0.10941.0

Did you find any workaround?

No response

Relevant log output

No response

davidwengier commented 1 month ago

@PureWeen @MackinnonBuck This is actually a MAUI issue, the targets file in the WebView SDK has the offending line:

https://github.com/dotnet/maui/blob/87253a5cfc6619237503c62b225b9e10561dedad/src/BlazorWebView/src/Maui/build/Microsoft.AspNetCore.Components.WebView.Maui.targets#L12

This line blindly includes all *.razor files as RazorComponent items, and since it's in a targets file it is included after the users .csproj file, so ignores any tweaks they do there.

See also https://github.com/dotnet/razor/issues/10954 and https://github.com/dotnet/maui/issues/25019

wjsimon commented 1 month ago

Work around via Directory.Build.targets from dotnet/razor#10954 works great, thank you very much :)

chsienki commented 4 weeks ago

Moving this to Maui.

jaredpar commented 4 weeks ago

@Redth can u move this to Maui?

similar-issues-ai[bot] commented 4 weeks ago

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

Zhanglirong-Winnie commented 2 weeks ago

This issue has been verified using Visual Studio 17.12.0 Preview 5 (9.0.0-rc.2.24503.2 & 8.0.92 & 8.0.3) & 17.11.5(7.0.101). Can repro this issue on android and windows platforms.