简体   繁体   中英

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.

I think you must set the launchSettings.json file port like this too

"WebApp1": {
  "commandName": "Project",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  },
  "applicationUrl": "https://localhost:5001/"
}

问题的根本原因是我在5000上的program.cs中配置了kestrel。将其更改为所需的端口号并且它可以工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM