2

我需要使用 Visual Studio Code 编译一个 .NET 解决方案。我里面tasks.json的任务声明如下:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "args": [
                "build",
                "${workspaceFolder}"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

现在按Ctrl+B我可以成功编译我的整个解决方案。不幸的是dotnet build,似乎输出了相对文件路径,并且从文档$msCompile问题匹配器仅适用于绝对路径。效果是,当在 Problems 面板内单击它时出现错误时会产生错误Unable to open XYZ.cs: File not found

我怎样才能正确配置dotnet build或 problemMatcher 工作?

4

1 回答 1

4

一个简单的解决方案是让dotnet build使用/property:GenerateFullPaths=true参数生成绝对文件路径。这是一个工作任务定义:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "args": [
                "build",
                "${workspaceFolder}",
                "/property:GenerateFullPaths=true"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}
于 2018-03-24T14:48:12.693 回答