如何配置visual studio代码以调试aps.net 5示例应用程序

时间:2021-10-17 15:30:30

I'm following the tutorial for a aspnet 5 getting started app http://docs.asp.net/en/latest/tutorials/your-first-mac-aspnet.html and modified it to use the simpler web api template project.

我正在关注aspnet 5入门应用程序http://docs.asp.net/en/latest/tutorials/your-first-mac-aspnet.html的教程并修改它以使用更简单的web api模板项目。

My question is: how do I configure the .vscode/launch.json file to run with debugging on?

我的问题是:如何配置.vscode / launch.json文件以便在调试时运行?

I can use the dnx web command from command line to run it, but how can I configure vscode so that I can get the nice debugger attached and launch the web command from hitting the green play button in vscode?

我可以从命令行使用dnx web命令来运行它,但是如何配置vscode以便我可以连接好的调试器并通过点击vscode中的绿色播放按钮启动web命令?

Here's the default launch.json

这是默认的launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "mono",
            "request": "launch",
            "program": "program.exe",
            "args": [],
            "cwd": ".",
            "runtimeExecutable": null,
            "env": {}
        },
        {
            "name": "Attach",
            "type": "mono",
            "request": "attach",
            "address": "localhost",
            "port": 5858
        }
    ]
}

1 个解决方案

#1


0  

This works for me: aspnet/cli-samples

这对我有用:aspnet / cli-samples

in your tasks.json file:

在你的tasks.json文件中:

{
    "version": "0.1.0",
    "command": "dotnet",
    "isShellCommand": true,
    "args": [],
    "tasks": [
        {
            "taskName": "build",
            "args": [],
            "isBuildCommand": true,
            "problemMatcher": "$msCompile"
        }
    ]
}

and in your launch.json:

并在您的launch.json中:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/HelloMvc.dll",
            "args": [],
            "cwd": "${workspaceRoot}",
            "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"
            },
            "sourceFileMap": {
                "/Views": "${workspaceRoot}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command.pickProcess}"
        }
    ]
}

#1


0  

This works for me: aspnet/cli-samples

这对我有用:aspnet / cli-samples

in your tasks.json file:

在你的tasks.json文件中:

{
    "version": "0.1.0",
    "command": "dotnet",
    "isShellCommand": true,
    "args": [],
    "tasks": [
        {
            "taskName": "build",
            "args": [],
            "isBuildCommand": true,
            "problemMatcher": "$msCompile"
        }
    ]
}

and in your launch.json:

并在您的launch.json中:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceRoot}/bin/Debug/netcoreapp1.0/HelloMvc.dll",
            "args": [],
            "cwd": "${workspaceRoot}",
            "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"
            },
            "sourceFileMap": {
                "/Views": "${workspaceRoot}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command.pickProcess}"
        }
    ]
}