Net8BlazorWebAssembly
Net8BlazorWebAssembly copied to clipboard
ASP.NET Core hosted Blazor WebAssembly app with .NET 8
Blazor WebAssembly in .NET 8
This project demonstrates how to build an ASP.NET Core hosted Blazor WebAssembly app with .NET 8 and how to upgrade existing apps to take advantage of the latest features.
To upgrade an existing ASP.NET Core hosted Blazor WebAssembly app to .NET 8:
- Update the project file to target
net8.0and package references to the latest .NET 8 versions (commit). - Move content from Client/wwwroot/index.html to Host.razor (commit):
- Update script to blazor.web.js.
- Replace
titletag withHeadOutletcomponent.
- Update Client/Program.cs (commit):
- Remove
builder.RootComponents.Add<HeadOutlet>("head::after").
- Remove
- Update Server/Program.cs (commit):
- Add
builder.Services.AddRazorComponents().AddWebAssemblyComponents(). - Remove
app.UseBlazorFrameworkFiles(). - Replace
MapFallbackToFile("index.html")withapp.MapRazorComponents<Host>().AddWebAssemblyRenderMode().
- Add
To enable prerendering:
- Update all components to support prerendering from the server (commit).
- In Host.razor replace the
id=apptag with<App @rendermode="@RenderMode.WebAssembly" />(commit).
Open issues:
- https://github.com/dotnet/aspnetcore/issues/49448
- https://github.com/dotnet/aspnetcore/issues/49056
- https://github.com/dotnet/aspnetcore/issues/49313