asp.net-corevisual-studio-codeportvscode-debuggerlaunch-configuration

VSCode debug ASP.NET Core app launch browser on specific port


I have the following .vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "My Web App",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build-frontend",
            "program": "${workspaceFolder}/src/MyWebApp/bin/Debug/netcoreapp2.2/MyWebAp.dll",
            "args": [],
            "cwd": "${workspaceFolder}/src/MyWebApp/bin/Debug/netcoreapp2.2",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart",
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development",
                "ASPNETCORE_URLS": "http://localhost:5001"
            },
            "launchBrowser": {
                "enabled": true,
                "args": "${auto-detect-url}",
                "windows": {
                    "command": "cmd.exe",
                    "args": "/C start ${auto-detect-url}",
                },
                "osx": {
                    "command": "open"
                },      
                "linux": {
                    "command": "xdg-open"
                }       
            },      
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/src/MyWebAppb/Views"
            },
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

However, debug session always opens up the browser at default port 5000. It doesn't honour the ASPNETCORE_URLS. Any advice and insight is appreciated.


Solution

  • Root cause of the problem is that I configure kestrel in program.cs on 5000. Change it to desired port number and it works.