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

Update .NET MAUI Blazor Hybrid and Web App template to use the new static web assets support in .NET 9 #25478

Open danroth27 opened 1 month ago

danroth27 commented 1 month ago

Description

The Blazor Web App project in the .NET MAUI Blazor Hybrid and Web App template is still using the older static files middleware. It should be updated to use the new static web assets support in .NET 9 (MapStaticAssets & friends) to match the Blazor Web App template.

Steps to Reproduce

  1. Create a .NET MAUI Blazor Hybrid and Web App project
  2. Look at Program.cs in the Blazor Web App project

Expected: Uses MapStaticAssets() and friends Actual: Uses UseStaticFiles()

Link to public reproduction project repository

No response

Version with bug

9.0.0-rc.2.24503.2

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Other (Tizen, Linux, etc. not supported by Microsoft directly)

Affected platform versions

Web

Did you find any workaround?

No response

Relevant log output

No response

dhalenggg commented 1 month ago

This issue has been verified using Visual Studio 17.12.0 Preview 3(9.0.0-rc.2.24473.5). Can repro this issue at Web platform.

Kaaybi commented 4 days ago

Excuse me I do not mean to hijack this issue but does this means that MAUI doesn't have currently the ability to use assets generated with MapStaticAssets()? I can't find any documentation or keyword like @Assets specific to MAUI?


On my side I have an existing solution with .NET MAUI Blazor Hybrid and I tried to use the new static web assets support in .NET 9. It works perfectly in Blazor Web but when launched with MAUI, bundles containing component isolated css are not retrieved.

In my App.razor:

<link` rel="stylesheet" href="@Assets["_content/App.Shared/App.Shared.bundle.scp.css"]" />

In my MAUI index.html (obviously missing something):

<link rel="stylesheet" href="_content/App.Shared/App.Shared.bundle.scp.css" />

When looking at MAUI dev network tab, my css file is naturally not looked up with the expected ETag so it ends up with a 404.