question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to launch the browser when running `dotnet run`

See original GitHub issue

It would be great if there was a way to run an ASP.NET Core app from the command line using dotnet run and have the default browser launch at the right URL. CLIs for other platforms let you do this. For example, with the Angular CLI you can do ng serve --open to both run the app and open the default browser.

This would be particularly useful for projects that you created using VS, which generate random ports for the server URLs.

There are already launchBrowser and launchUrl properties the launch profiles in launchSettings.json that let you specify that you want this behavior in VS.

We would also want this to work with dotnet watch without having the browser pop up multiple times, which may require some coordination.

@mlorbetske @natemcmaster @livarcocc @KathleenDollard

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:44
  • Comments:28 (17 by maintainers)

github_iconTop GitHub Comments

11reactions
maxildcommented, Mar 10, 2021

I have to support https://github.com/dotnet/sdk/issues/9038#issuecomment-656351718

Working with Blazor WASM on Linux (where firefox often is the default browser for good reasons: xdg-open will use firefox`) is not easy out of the box, when Chrome is the only supported dev browser (on Linux).

My current solution is to use 2 terminals

Terminal 1

$ dotnet run --no-launch-profile 

Terminal 2

$ google-chrome http://localhost:5000

One strange thing is that I can’t seem to get this to work with dotnet watch. That is

Terminal 1

$ dotnet watch run --no-launch-profile 

does use the default launchSettings.json (launchBrowser, inspectUri, applicationUrl etc) config values for the app, I have no idea why the child dotnet run is not getting the --no-launch-profile switch??? May be my mistake???

REQUEST:

Add new browsers field with possible values firefox, chrome, edge etc. to launchSettings.json

"profiles": {
    "BlazorWasmApp": {
      "commandName": "Project",
      "dotnetRunMessages": "true",
      "launchBrowser": true,
      "browsers": ["chrome"], <---- REQEUST: Please add this feature
      "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
      "applicationUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }

NOTE: Each opened browser should probably also have config values for extra args. I guess this all starts to be a bit platform dependent, but a design should be possible accross windows, macos and the dotnet supported linux distros.

7reactions
logcornercommented, May 12, 2021

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

asp.net - Run app and launch browser from command line
I don't think dotnet can start a browser. It will just start the server and use the applicationUrl and environment variables but will...
Read more >
dotnet run command - .NET CLI
The dotnet run command provides a convenient option to run your application from the source code with one command.
Read more >
How to suppress dotnet whatch run to open a browser
Using the launchSettings.​​ The launchBrowser property in the profiles defines whether the browser should be opened or not. Set it to false in ......
Read more >
Don't Launch a Browser Running ASP.NET Core Back-end ...
This is going to be a quick post on how to stop that browser launch. The following are the previous Web Template Studio...
Read more >
Run and debug .NET Core and ASP. ...
Using launch settings (launchSettings.json) to run and debug .NET Core apps in JetBrains Rider.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found