-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing one
Milestone
Description
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
ComputeRunArgumentsto 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 Aspire scenarios
- Serves WASM framework files via
UseBlazorFrameworkFiles() - Serves static files from wwwroot
- Provides fallback to
index.html
2. Exposes configuration endpoint
- Maps
/_blazor/_configurationendpoint - 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
.propsand.targetsfiles - Overrides
ComputeRunArgumentsto launch Gateway with static asset paths - Passes
--contentroot,--staticwebassets,--staticwebassetsendpointsarguments
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.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.MapFallbackToFile("index.html");
app.MapConfigurationEndpoint("/_blazor/_configuration");
app.Run();Metadata
Metadata
Assignees
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing one