How to launch swagger url through vscode?

Viewed 2373

I am trying to launch swagger UI in browser using dotnet run command. Here is what I have tried in launch.json file. Expected outcome is that it should launch browser at the specified url and open swagger UI automatically. FYI I am using dotnet5 and created new web api project that already has swagger baked in. It doesn't launch the browser.

enter image description here

enter image description here

enter image description here

2 Answers

If you are using dotnet run command then its a known limitation that it doesn't launch a browser.

Please refer to this link for confirmation

While it doesn't launch it, it will still have your project running just means you manually have to type it in browser or use one of the workarounds listed in that issue.

Use compounds launch settings

"configurations": [
    {
        "name": ".NET Core Launch (console)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceFolder}/src/WebApi/bin/Debug/net7.0/YourWebDll.dll",
        "args": [],
        "cwd": "${workspaceFolder}",
        "stopAtEntry": false,
        "console": "internalConsole"
    },
    {
        "name": "Launch Chrome",
        "request": "launch",
        "type": "chrome",
        "url": "https://localhost:5001/swagger/index.html",
        "webRoot": "${workspaceFolder}"
    }
],
"compounds": [
    {
        "name": ".Net Core & Chrome",
        "configurations": [".NET Core Launch (console)","Launch Chrome"]
    }
]

This will run your app and launch chrome at the URL you want.

Related