maui icon indicating copy to clipboard operation
maui copied to clipboard

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

Open wjsimon opened this issue 1 year ago • 5 comments

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

wjsimon avatar Oct 22 '24 11:10 wjsimon

@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

davidwengier avatar Oct 22 '24 21:10 davidwengier

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

wjsimon avatar Oct 23 '24 07:10 wjsimon

Moving this to Maui.

chsienki avatar Oct 24 '24 17:10 chsienki

@Redth can u move this to Maui?

jaredpar avatar Oct 24 '24 17:10 jaredpar

We've found some similar issues:

  • #25447 , similarity score: 100%

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.

similar-issues-ai[bot] avatar Oct 24 '24 17:10 similar-issues-ai[bot]

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.

Zhanglirong-Winnie avatar Nov 07 '24 06:11 Zhanglirong-Winnie