我的目的是使用与默认值5000不同的端口启动VSCode调试器,为此我在“args”数组(命令行参数)和ASPNETCORE_URLS env变量中指定了url。我在Visual Studio Code调试器中使用以下launch.json配置:
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/MotelsBack.API/bin/Debug/netcoreapp2.0/MotelsBack.API.dll",
"args": ["urls=http://localhost:6000"],
"cwd": "${workspaceFolder}/MotelsBack.API",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"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",
//"ASPNETCORE_URLS": "http://localhost:6000" --Commented, however this don't work also
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
调试器在指定的端口上启动,显示:
调试器输出显示可以通过我在之前的两个选项中指定的URL访问该应用程序,但是当我从任何资源管理器访问此URL时未找到应用程序,它只是不起作用,但如果我删除launch.json中的端口定义使用它工作的5000默认端口。
Visual Studio Code调试器不接受其他端口吗?
答案 0 :(得分:4)
端口6000是浏览器认为不安全的端口,因此safari和chrome无法连接到它们(Safari上的WebKitErrorDomain:103和chrome上的ERR_UNSAFE_PORT)。
为ASPNETCORE_URLS
环境变量使用另一个非"不安全的#34;端口,它应该可以正常工作。
目前在ASP.NET Core 2.0中无法通过--urls
传递它,但由于this issue,它将在2.1中(请参阅问题解决方法)。