-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support dotnet watch launching the aspire dashboard URL #44262
Description
See microsoft/aspire#3812. Today dotnet watch for aspire will launch the browser (incorrectly without the auth token #44259) but still doesn't launch the browser preserving the query string. This means the user needs to log in manually which hurts the user experience.
We solve this in VS and VS code and dotnet watch should be next. The way it works there is when launching the app host project, VS and VS Code generate the auth token for the dashboard and pass it to the app host process via the DOTNET_DASHBOARD_FRONTEND_BROWSERTOKEN environment variable. The app host then uses this token (instead of generating one itself) to configure the dashboard. The browser launching logic in VS and VS Code factors this in such that the generated key is appended to the "applicationUrl" property in the active launch profile for the app host project as a query string value.
The flow becomes:
dotnet watchis run against the app host projectdotnet watchrecognizes it's launching an Aspire app host project and as well as setting up to run with the Aspire IDE protocol, it generates an auth token for the Aspire dashboard and passes it into the launched app host process via theDOTNET_DASHBOARD_FRONTEND_BROWSERTOKEN- Assuming the launch profile of the app host project is configured to launch a browser (i.e.
"launchBrowser": true,in the launchSettings.json file),dotnet watchmonitors the console output of the app host project for the\nNow listening on: [dashboard_address]\nlog message, where[dashboard_address]is a valid https or http URI, which indicates the dashboard web server has started listening and the address it's listening on. - Once the message is detected, if the
"launchUrl"launch profile property:- Has no value:
dotnet watchconstructs the launch URL using the following format:[dashboard_address]/login?t=[DOTNET_DASHBOARD_FRONTEND_BROWSERTOKEN], where the value for[dashboard_address]is replaced with the value extracted from the log message, and[DOTNET_DASHBOARD_FRONTEND_BROWSERTOKEN]is replaced with the value passed in the respective environment variable, e.g.https://localhost:17004/login?t=9af73ba37bba75028edacef58e63b04c - Has a value: If the value is an absolute URI,
dotnet watchuses it as the launch URL. If the value is a relative URL,dotnet watchappends it to the[dashboard_address]value and uses that as the launch URL.
- Has no value:
dotnet watchlaunches the browser using the constructed launch URL- Note: An optional step to take before launching the browser (which VS does) is to attempt to connect a client socket to the address in the launch URL and not continue with the browser launching until the socket connection completes successfully, timing out after some period and printing a message if a socket can't be established. The socket is simply used to detect the readiness of the server to accept client connections before launching the browser so as to avoid the browser being launched too soon and the user seeing an error.