VS Code $ msCompile problemMatcher不使用相对文件路径

时间:2018-03-24 14:48:13

标签: .net visual-studio-code dotnet-cli

我需要使用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似乎输出了相对文件路径,而documentation $msCompile问题匹配器只能使用绝对路径。结果是,当在“问题”面板中单击它时出现错误时,会产生错误Unable to open XYZ.cs: File not found

如何正确配置dotnet build或problemMatcher?

1 个答案:

答案 0 :(得分:3)

一个简单的解决方案是让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"
        }
    ]
}