3.6 KiB
Blazor Project Configuration
This document explains the hosting model used in this project, how to identify it, and how to switch between different Blazor setups.
Current Project Type: Blazor Web App (.NET 8+)
This project uses the Blazor Web App template introduced in .NET 8. This is a unified model that supports multiple rendering modes:
- Static Server-Side Rendering (Static SSR): The default mode for most components in this project.
- Interactive WebAssembly: Currently configured as the interactive hosting model.
1. How to tell it's using WebAssembly
You can identify the hosting model by looking at the following locations:
AOW4/Program.cs:builder.Services.AddRazorComponents().AddInteractiveWebAssemblyComponents();registers the WebAssembly services.app.MapRazorComponents<App>().AddInteractiveWebAssemblyRenderMode()enables the WebAssembly rendering mode.
- Project Structure:
AOW4(Server Project): Handles the initial request and serves the static assets.AOW4.Client(Client Project): Contains components and logic intended to run in the user's browser via WebAssembly.
- Project References (
AOW4.csproj):- The server project references the client project:
<ProjectReference Include="..\AOW4.Client\AOW4.Client.csproj" />. - It also includes the package
Microsoft.AspNetCore.Components.WebAssembly.Server.
- The server project references the client project:
2. Switching Between Setups
Switching to Blazor Server (Interactive Server)
If you want components to run on the server via SignalR instead of WebAssembly:
- Update
Program.csin the Server project:// Add service registration builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); // Add this line // Enable render mode app.MapRazorComponents<App>() .AddInteractiveServerRenderMode(); // Add this line - On your Components:
Change the render mode attribute at the top of your
.razorfiles:@rendermode InteractiveServer
Using Interactive Auto
Auto mode uses Blazor Server while the WebAssembly bundle is downloading, then switches to WebAssembly on subsequent visits.
- Update
Program.cs: Ensure bothAddInteractiveServerComponents()andAddInteractiveWebAssemblyComponents()are registered, and both render modes are added toMapRazorComponents<App>(). - On your Components:
@rendermode InteractiveAuto
Switching to ONLY Blazor Server
To remove WebAssembly entirely:
- Remove the
AOW4.Clientproject reference fromAOW4.csproj. - Remove all "WebAssembly" related calls in
Program.cs. - Delete the
AOW4.Clientproject. - Ensure all components are moved to the
AOW4(Server) project.
3. Production Release for Blazor WebAssembly
Since this is a hosted Blazor Web App, you publish the Server project. The build process automatically handles the WebAssembly client assets.
Command
Run this command from the solution root:
dotnet publish AOW4\AOW4.csproj -c Release
What happens during publish:
- Server Compilation: The ASP.NET Core host project is compiled.
- Client Compilation: The
AOW4.Clientproject is compiled into WebAssembly (.wasm) and static assets. - Asset Integration: All client-side files (WASM, JS, CSS, images) are placed in the
wwwrootfolder of the published server output. - Output Directory: The final ready-to-deploy application will be in
AOW4\bin\Release\net10.0\publish\.
To deploy, simply copy the contents of the publish folder to your web server (IIS, Azure App Service, Nginx, etc.).