Making VS Code and OmniSharp Open the Browser to a Specific URL for a .NET Application
I use VS Code a lot, but I’m not a fan of how it ignores the launchUrl property in the launchSettings.json file.
If you don’t know what I mean, create a new project -
dotnet new webapi -o MyWebApiOpen the launchSettings.json file, you will see something like -
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5289",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},In VS Code press F5 to run the application. The browser opens to https://localhost:5289/.
I want it to open to https://localhost:5289/weatherforecast.
Here’s the fix.
Open the .vscode/launch.json file, and look for the section serverReadyAction. Add the uriFormat -
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)",
"uriFormat": "%s/weatherforecast"
},Now when you launch the project, it will open to https://localhost:5289/weatherforecast.
My default browser is Firefox, but if I want the application to open in Chrome or Edge, I can change the action to one of the following -
debugWithChromedebugWithEdge
