dotnet / dotnet/maui

Blazor Hybrid MAUI unpackaged single-file apps do not extract Application.styles.css (scoped CSS) at runtime

Open
#33,587 4 comments 0 reactions 0 assignees View on GitHub
area-blazor platform/windows s/triaged s/verified t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

When publishing a .NET 10 MAUI Blazor Hybrid application as an unpackaged, self-contained, single-file Windows executable, the generated Blazor scoped CSS bundle (.styles.css) is not extracted at runtime, even though it is present in the publish output.

This results in missing styles at runtime because BlazorWebView expects the scoped CSS bundle (.styles.css) to be present under wwwroot in the runtime extraction directory (%LOCALAPPDATA%\Temp\.net\\\wwwroot), but the file is not extracted there when running the single-file executable. I am not sure the CSS file is even included in the single-file executable.

This appears to be an interaction issue between:
* Razor scoped CSS static web assets
* MAUI Blazor Hybrid
* .NET single-file bundling/extraction

##Expected Behavior##

The runtime extraction directory (`%LOCALAPPDATA%\Temp\.net\\\wwwroot`) should contain MauiApp1.styles.css:

wwwroot/
├─ index.html
└─ *MauiApp1.styles.css*

So that Blazor scoped CSS is applied correctly at runtime.

##Actual Behavior##

The runtime extraction directory contains:
wwwroot/
├─ index.html
MauiApp1.styles.css is missing, even though it exists in the publish output.

##Request##

Please suggest a supported workaround or fix for the described issue.

If this is a bug, guidance on where it should be fixed would be appreciated. I would be happy to contribute, but would need direction on the appropriate place to start.

Is this a regression from previous behaviour?
* This behaviour exists in .net 8.

### Steps to Reproduce

1. Create a .NET MAUI Blazor Hybrid App
2. Add scoped CSS to any Razor component (e.g. MainLayout.razor.css)

1. Publish using:
```
dotnet publish ^
-f net8.0-windows10.0.19041.0 ^
-r win-x64 ^
-p:SelfContained=true ^
-p:WindowsAppSDKSelfContained=true ^
-p:PublishSingleFile=true ^
-p:WindowsPackageType=None
```

1. Observe publish output contains:

publish/
├─ MauiApp1.exe
└─ wwwroot/
---├─ index.html
---└─ MauiApp1.styles.css

1. Run the published single-file EXE

Inspect runtime extraction directory:

`%LOCALAPPDATA%\Temp\.net\\\wwwroot` and notice how it is missing MauiApp1.styles.css

### Link to public reproduction project repository

https://github.com/Abdulrhman5/SingleFileMauiIssue

### Version with bug

10.0.10

### Is this a regression from previous behavior?

Not sure, did not test other versions

### Last version that worked well

Unknown/Other

### Affected platforms

Windows

### Affected platform versions

_No response_

### Did you find any workaround?

Nope, I hope someone can suggest any.

### Relevant log output

```shell

```

Contributor guide

Open the contributing guide

Research direction

Start with the linked SingleFileMauiIssue reproduction project and run the supplied dotnet publish command for the unpackaged, self-contained Windows single-file app. Compare the publish wwwroot with %LOCALAPPDATA%\Temp\.net\\\wwwroot while checking how the scoped CSS bundle is handled. Done means the generated .styles.css file is extracted and scoped styles apply at runtime.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, css
Domain
build-system, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.