dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.65k stars 416 forks source link

Ability to automatically open a web project on debug #4608

Open mip1983 opened 3 months ago

mip1983 commented 3 months ago

Background and Motivation

It would help with debugging productivity if you could automatically launch web projects with Aspire when you start debugging in Visual Studio 2022 as you can if you're not using Aspire with startup/multiple-startup projects.

Proposed API

namespace Aspire.Hosting;

public static class ContainerResourceBuilderExtensions
{
     public static IResourceBuilder<T> OpenEndPointsOnDebug<T>(this IResourceBuilder<T> builder,  string openEndPointsOnDebug []) where T: ContainerResource
}

Usage Examples

builder.AddProject<Projects.web_Web>("web")
         .OpenEndPointsOnDebug(["https"]) 

Which would trigger the Aspire dashboard to open that endpoint in a new tab once it's started (only if debugger is attached).

Alternative Designs

builder.AddProject<Projects.web_Web>("web", openEndPointsOnDebug: ["https"])

Risks

User might try to set a project to open to which the debugger doesn't automatically attach like a Blazor wasm project (would be good if VS2022 could though).

mitchdenny commented 3 months ago

So this is specifically about opening multiple web projects? It is already possible to change the launch URL for the apphost. If you set launchUrl to the app you want to open it will open the dashboard but then redirect to the URL you have specified in launchUrl.