Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode launch.json debug and open specific url

Given the following auto-generated Visual Studio Code launch.json config:

I'd like this to launch the browser to localhost:5000/swagger when I debug, but I've tried half a dozen different things and nothing works. It just opens to localhost:5000. What am I missing here? There's no general documentation (that I could find) on all of the attributes available aside from hitting Ctrl+space to see a list, which doesn't help much.

I left out my failed attempts at getting this to work how I want...

{
    "name": "Launch Demo.Api",
    "type": "coreclr",
    "request": "launch",
    "preLaunchTask": "build",
    "program": "${workspaceRoot}/Demo.Api/bin/Debug/netcoreapp2.1/Demo.Api.dll",
    "args": [],
    "cwd": "${workspaceRoot}/Demo.Api",
    "stopAtEntry": false,
    "launchBrowser": {
        "enabled": true,
        "args": "${auto-detect-url}",
        "windows": {
            "command": "cmd.exe",
            "args": "/C start ${auto-detect-url}"
        },
        "osx": {
            "command": "open"
        },
        "linux": {
            "command": "xdg-open"
        }
    },
    "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
    }
}
like image 792
Kizmar Avatar asked Aug 17 '18 17:08

Kizmar


People also ask

How do I open a URL in Vscode?

Opening VS Code with URLs You can use the URL in applications such as browsers or file explorers that can parse and redirect the URL. For example, on Windows, you could pass a vscode:// URL directly to the Windows Explorer or to the command line as start vscode://{full path to file} .

How do I launch VS code json?

To create a launch.json file, click the create a launch.json file link in the Run start view. If you go back to the File Explorer view (Ctrl+Shift+E), you'll see that VS Code has created a .vscode folder and added the launch.json file to your workspace.

What is CWD launch json?

There is a launch.json file...there you should be able to set the cwd property...( cwd stands for current working directory )

How do I enable auto link in Vscode?

You enable auto attach by running Debug: Toggle Auto Attach command from the Command Palette, and once activated you can toggle auto attach from the Status Bar as well.


1 Answers

this one also works for me on VSCode 1.39.2

// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
    "action": "openExternally",
    "pattern": "\\bNow listening on:\\s+(https?://\\S+)",
    "uriFormat": "%s/swagger"
}, 
like image 95
Soren Avatar answered Sep 27 '22 20:09

Soren