dotnet / project-system

The .NET Project System for Visual Studio
MIT License
969 stars 387 forks source link

How to make VS launch a browser when debugging console apps? #6767

Closed ivan-prodanov closed 3 years ago

ivan-prodanov commented 3 years ago

Visual Studio Version:16.8.1, .NET Core 5. Summary: I'm trying to make the VS debugger launch a browser when running a console app launch (the console works like an asp.net core app but it's intentionally a console type) via a configuration (say, only if in Debug). My problem is that the debugger in Visual Studio completely ignores the option "launchBrowser" in the launchSettings.json file. So far I found that adding the following property (Only in Debug configuration) makes VS launch the browser when running the app: <ProjectCapability Include="DotNetCoreWeb" />.

However, this property requires the project to be reloaded in Visual Studio everytime configurations are switched between debug/release.

Is there an easier/better/more feasible way to make VS launch a browser when running a console app? What is using the "launchBrowser" option from the launchSettings.json file?

jjmew commented 3 years ago

@ivan-prodanov Is the project capability added to all configurations?

ivan-prodanov commented 3 years ago

Yup.

jjmew commented 3 years ago

@ivan-prodanov This doesn't fall into an area that we see as supported. Would you tell us a little bit more about why you can't use an ASP.NET Core project? we might be able to help

ivan-prodanov commented 3 years ago

@jjmew Thanks, I'll give you more details. I'd like to have a project that launches a browser when the debugger starts in VS/code, but with minimal set of dependencies. E.g Blazor does this without relying on ASP.NET thanks to making the blazor projects externally hosted (by a devServer) - the devServer loads the blazor set of assemblies in mono.wasm and then calls the app's entry point through an interop from JS.

I could use the Microsoft.NET.Sdk.BlazorWebASsembly SDK but it copies every file from the browser-wasm runtime (because the props file in the Blazor SDK specifies RuntimeIdentifier as "browser-wasm"). I don't want that to happen.

Ultimately the most minimalistic approach I ended up with was using this project capability: <ProjectCapability Include="DotNetCoreWeb" />

Combined with the RunCommand and RunArguments properties set, you can make a class library launch a browser when debugged through VS and rely on minimal amount of dependencies and externally load it in wasm and debug that library when a method is invoked from js. Essentially the debugger only launches a browser with remote debugging and connects to the "inspectUri" in appSettings.json and just listens to the mono DebugProxy, that's all it does.

I opened this issue hoping there's a an even more minimal approach. What specifically allows a browser to be launched after specifying the DotNetCoreWeb capability?

In closing, wasm projects have to be debuggable through a browser when launched from VS even though they are externally hosted. The appSettings.json contains a property "inspectUri" which is used by the VS debugger to connect to the Debug proxy, which connects the debugger in VS with the chrome session launched with remote debugging by VS.

jjmew commented 3 years ago

@ivan-prodanov thank you for the explanation. We don't have an additional way that we could recommend that will be minimalistic. As of now, we don't have plan to add an approach that will help.