Summary
Create a Gateway package for standalone Blazor WebAssembly applications that enables seamless Aspire integration without requiring a hosted server project.
Background
When integrating standalone Blazor WebAssembly applications with Aspire, we currently need to:
- Remove the DevServer dependency
- Create a custom Gateway project that serves static files
- Expose a configuration endpoint (
/_blazor/_configuration) for OTEL and service discovery settings
- Add Aspire service defaults integration
- Set up MSBuild targets to override
ComputeRunArguments to launch Gateway instead of the WASM project
This is demonstrated in the AspireWithBlazorStandalone playground sample in https://github.com/dotnet/aspire.
Proposed Solution
Create a Microsoft.AspNetCore.Components.WebAssembly.Gateway package that:
1. Replaces DevServer for production scenarios
- Uses MapStaticAssets to serve blazor files.
- Serves static files from wwwroot
- Provides fallback to
index.html
2. Exposes configuration endpoint
- Maps
/_blazor/_configuration endpoint
- Returns OTEL settings (
OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS)
- Returns service discovery configuration (
services:*)
3. Integrates with Aspire
- Adds service defaults (OpenTelemetry, health checks, service discovery)
- Maps default endpoints (
/health, /alive)
4. MSBuild integration
- Provides
.props and .targets files
- Overrides
ComputeRunArguments to launch Gateway with static asset paths
- Passes
--contentroot, --staticwebassets, --staticwebassetsendpoints arguments
Example Gateway Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
var contentRoot = builder.Configuration["contentroot"];
if (!string.IsNullOrEmpty(contentRoot))
{
builder.Environment.ContentRootPath = contentRoot;
builder.Environment.WebRootPath = Path.Combine(contentRoot, "wwwroot");
}
var app = builder.Build();
app.MapDefaultEndpoints();
app.MapStaticAssets();
app.MapFallbackToFile("index.html");
app.MapConfigurationEndpoint("/_blazor/_configuration");
app.Run();
Summary
Create a Gateway package for standalone Blazor WebAssembly applications that enables seamless Aspire integration without requiring a hosted server project.
Background
When integrating standalone Blazor WebAssembly applications with Aspire, we currently need to:
/_blazor/_configuration) for OTEL and service discovery settingsComputeRunArgumentsto launch Gateway instead of the WASM projectThis is demonstrated in the
AspireWithBlazorStandaloneplayground sample in https://github.com/dotnet/aspire.Proposed Solution
Create a
Microsoft.AspNetCore.Components.WebAssembly.Gatewaypackage that:1. Replaces DevServer for production scenarios
index.html2. Exposes configuration endpoint
/_blazor/_configurationendpointOTEL_EXPORTER_OTLP_ENDPOINT,OTEL_EXPORTER_OTLP_HEADERS)services:*)3. Integrates with Aspire
/health,/alive)4. MSBuild integration
.propsand.targetsfilesComputeRunArgumentsto launch Gateway with static asset paths--contentroot,--staticwebassets,--staticwebassetsendpointsargumentsExample Gateway Program.cs