Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dotnet watch launching the aspire dashboard URL #44262

Open
davidfowl opened this issue Oct 17, 2024 · 1 comment
Open

Support dotnet watch launching the aspire dashboard URL #44262

davidfowl opened this issue Oct 17, 2024 · 1 comment
Labels
Area-Watch Aspire untriaged Request triage from a team member

Comments

@davidfowl
Copy link
Member

davidfowl commented Oct 17, 2024

See dotnet/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 watch is run against the app host project
  • dotnet watch recognizes 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 the DOTNET_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 watch monitors the console output of the app host project for the \nNow listening on: [dashboard_address]\n log 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 watch constructs 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 watch uses it as the launch URL. If the value is a relative URL, dotnet watch appends it to the [dashboard_address] value and uses that as the launch URL.
  • dotnet watch launches 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.
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch untriaged Request triage from a team member labels Oct 17, 2024
@davidfowl davidfowl added Area-Watch and removed Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch labels Oct 17, 2024
@davidfowl davidfowl changed the title Support dotnet watch launching the URL with the query string in it Support dotnet watch launching the aspire dashboard URL Jan 16, 2025
@davidfowl
Copy link
Member Author

@tmat can you attempt to implement this in dotnet watch for aspire projects?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Watch Aspire untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

1 participant