Repository navigation
feat(aspire): bake service addresses into WebAssembly and Android apps - #3311
Kunal22shah wants to merge 12 commits into
Conversation
4219b64 to
094c861
Compare
|
Tick the box to add this pull request to the merge queue (same as
|
094c861 to
e466450
Compare
carldebilly
left a comment
There was a problem hiding this comment.
The baking design is sound for a first version, and safer than what Aspire.Hosting.Maui does: only service addresses are written (MAUI writes every variable, OTLP headers included), they are read in Debug only, and every warning names its cause. Hooking _GenerateEnvironmentFiles with RuntimeEnvironmentVariable is the same hook MAUI relies on, so no objection there. The overall review of the stack is on #3309.
Before merge:
- Public naming.
WithBakedEnvironmentnames the mechanism. For WebAssembly, the longer-term direction is runtime delivery, asAspire.Hosting.Blazordoes with its gateway (configuration read before boot, APIs proxied same-origin, OTLP proxied), which needs a pre-boot hook inUno.Wasm.Bootstrap. A mechanism-neutral name such asWithClientEnvironmentkeeps that door open without another rename. Knock-on: both overloads, the head log messages that cite it, the how-to and the spec. - Android SDK floor.
RuntimeEnvironmentVariableneeds the .NET 10.0.300 SDK; the how-to should state it next to the existing warning.
Later (fine as follow-ups):
- Dev tunnels as a documented, tested path for the emulator and devices, which is what lets MAUI drop
10.0.2.2and the hand-written network security configuration. - A values file outside
obj(e.g. a temp folder keyed by the project path), so a customBaseIntermediateOutputPathor artifacts output does not leave a stray folder and a killed AppHost cannot leave addresses behind.
Nits:
UnoAppBuilderExtensions.cs:251-255copies the environment into aListof unnamed tuples only to pass it as anIEnumerable; aSelectinto named tuples does the same.UnoAppBuilderExtensions.cs:295-324:string.Joinruns for the warnings without anIsEnabledguard (AGENTS.md); passing the lists as arguments lets the logger join them.ProjectAssets.cs:11:"libraries"u8instead ofEncoding.UTF8.GetBytes("libraries").BakedEnvironment.cs:213: the upper-cased prefix is rebuilt for every pair; hoist it per service.
e466450 to
72b364d
Compare
72b364d to
a312556
Compare
kazo0
left a comment
There was a problem hiding this comment.
Validated the stack end to end on Windows, using local packages from dev/ks/aspire-baking (a312556) in a fresh dotnet new unoapp (Kiota, desktop + WebAssembly + Android) with an ASP.NET Core API and an Aspire 13.6.5 AppHost, driven through the Aspire CLI 17.
- Client (#3309):
- Discovery resolves from the environment, and Aspire's address wins over a
servicessection in settings. - Against a 503 endpoint: GET reaches the API 4 times, POST once. With
UseResilience = false, Kiota's own retries send POST 4 times. - Telemetry is exported in Debug/Development and not in Release/Production, checked against a fake OTLP receiver.
DiagnosticHandlershowsAuthorization: [redacted]and no query string.
- Discovery resolves from the environment, and Aspire's address wins over a
- AppHost (#3310):
- A second head waits while another builds ("Waiting for another head of 'app' to finish building").
- The target-framework error is clear.
WithArgsproperties reach the build.- Stopping a head closes the app (desktop and Android). Killing the AppHost left no processes behind.
- Values written into WebAssembly and Android (#3311):
- Only service addresses are written. The secret is left out and the log names it;
WithClientEnvironmentopts a variable in. - The WebAssembly app in headless Edge called the API over https, and the CORS preflight passed.
- Android (API 36 emulator, workload 37.2.31) called the API over http via
10.0.2.2, with uppercase names. - An IDE-style build keeps the values, a Release publish carries none, and a clean stop removes the file.
- The lease renews every minute; a killed AppHost's file is removed with
UNOASPIRE103. - An https-only API gives the emulator warning.
- Only service addresses are written. The secret is left out and the log names it;
Not covered: Hot Reload (in progress), WebAssembly over plain http, macOS/Linux, physical devices, AOT.
|
Follow-up: Hot Reload also checked, on the desktop head started by the AppHost, with |
|
Docs check for
Not blocking. |
macOS validation: values written into WebAssembly buildsPackages Everything matches the Windows baseline.
Differences from Windows:
Android (23–25) wasn't run on the Mac. |
|
Thanks for the docs check. Done in 1455bcb: the how-to is now linked from the References list in I left out the Kiota note in the overview: the how-to already covers how |
…and Android apps - before a WebAssembly or Android head is built, the AppHost writes its allow-listed values into the app's obj/uno-aspire; nothing is written when the environment fails to resolve - Uno.Extensions.Aspire ships the build logic that reads them in Debug builds, IDE builds included: WasmShellMonoEnvironment for WebAssembly, RuntimeEnvironmentVariable for Android - Android: loopback service addresses get 10.0.2.2 over http only; names uppercased - WithClientEnvironment opts a variable in; the head's log names what was written or left out - the AppHost removes the file at its start and stop; build warnings UNOASPIRE101 and UNOASPIRE102 name a format or Android SDK mismatch - build tests run that logic with MSBuild
- the AppHost renews each values file every minute while it runs - a Debug build ignores a file older than five minutes, with warning UNOASPIRE103, instead of baking dead addresses
- The check read the restore from before the head's build, so a reference changed by a WithArgs property warned one start late
- Install through the Aspire UnoFeature, with the package reference for older SDKs - Require the Http feature only - UNOASPIRE101 is about the file format, not the package versions
1455bcb to
770360a
Compare
Stack 3 of 4. Based on #3310 (AppHost package), which is based on #3309 (client package); next: #3317 (dev server for Hot Reload).
PR Type
What is the current behavior?
The WebAssembly and Android heads run, but their apps don't get the API's address: a browser has no process environment, and an Android app doesn't inherit the one
dotnet runhad.What is the new behavior?
Before a WebAssembly or Android head is built, the AppHost writes the addresses of the services it references into the app's
obj/uno-aspirefolder. Build logic shipped inUno.Extensions.Aspirereads them into the app, in Debug builds only:WasmShellMonoEnvironment).dotnet run -eadds (RuntimeEnvironmentVariable). Alocalhostaddress becomes10.0.2.2, overhttponly, and names are uppercased.Safety:
WithClientEnvironment("Name")opts one variable in on purpose. If the environment fails to resolve, nothing is written.UNOASPIRE103), instead of baking addresses nobody serves.Every build reads it, IDE builds included. Because the file is in the app's own folder, building in your IDE while the head runs keeps the address.
Warnings point at the cause when the app gets no address:
Uno.Extensions.Aspire;UNOASPIRE102; the package version mismatch isUNOASPIRE101);UNOASPIRE103);https.Reviewer's guide
BakedEnvironment.cs: the allow-list (Plan), the Android rules (ForAndroidEmulator) and writing the file.ClientEnvironment.cs: writing the file before the build, removing it with the AppHost, and the head's log.src/Uno.Extensions.Aspire/buildTransitive/Uno.Extensions.Aspire.targets.Given_WebAssemblyHead,Given_AndroidEmulatorHead: application model.Given_AppBuildLogic: runs the real build logic with MSBuild against what the AppHost wrote; Debug, Release, publish, other configuration, other version, Android SDK that ignores the values.doc/Learn/Http/HowTo-Aspire.mdfor the whole feature (desktop, WebAssembly, Android) and its TOC entry. The spec is in feat(aspire): add the Uno.Extensions.Aspire client package #3309.Verified on the sample:
httpand overhttps. An IDE-styledotnet buildduring the run kept the address.httpto10.0.2.2only.PR Checklist
Other information
🤖 Generated with Claude Code