This project demonstrates how to upgrade Blazor Server apps to .NET 8 and take advantage of the latest Blazor features.
To upgrade an existing Blazor Server app to .NET 8:
- Update the project file to target
net8.0
and package references to the latest .NET 8 versions. - Move the contents of App.razor to Routes.razor.
- Move content from Pages/_Host.cshtml to App.razor:
- Update script to blazor.web.js.
- Replace tag helpers with Blazor equivalents.
- Update Program.cs:
- Replace
AddServerSideBlazor()
withAddRazorComponents().AddInteractiveServerComponents()
. - Add
app.UseAntiforgery()
. - Replace
MapBlazorHub()
withMapRazorComponents<App>().AddInteractiveServerRenderMode()
. - Remove
app.MapFallbackToPage("/_Host");
.
- Replace