记一次VSCode调试Aspnetcore.Doc时遇到的“couldn't find task build”问题

Aspnetcore.Doc是微软开源的netcoreDemo项目,包括官方文档中所有的源代码,是非常好的dotnetcore学习资源,项目地址为https://github.com/aspnet/AspNetCore.Docs

在使用vscode调试该项目时,首先遇到了如题目所述的问题。vscode调试时需要launch.json和task.json两个配置文件,在创建task文件后,问题解决。task文件的内容可参考以下代码:

tasks.json
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "command": "",
    "args": [],
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "shell",
            "args": [
                "build"
            ],
            "options": {
                "cwd": "${workspaceRoot}"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "problemMatcher": "$msCompile"
        }
    ]
}

注意,{workspaceRoot}是使用vscode的OpenFolder打开的路径。如果.csproj不在此路径下,需要手动修改'cwd'的内容,以下是我使用的路径:

 "options": {
        "cwd": "${workspaceRoot}/aspnetcore/fundamentals/servers/kestrel/samples/2.x/KestrelSample"
},

成功后Debug Console中显示调试信息,此时可命中断点

image.png

你可能感兴趣的:(记一次VSCode调试Aspnetcore.Doc时遇到的“couldn't find task build”问题)