.netvisual-studio-codedotnet-clivscode-problem-matcher

VS Code $msCompile problemMatcher doesn't work with relative file path


I need to compile a .NET solution using Visual Studio Code. My task inside tasks.json is declared like:

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

Now pressing Ctrl+B I can successfully compile my entire solution. Unfortunately dotnet build seems to output relative file path, and from the documentation the $msCompile problem matcher works only with absolute path. The effect is that when there is an error clicking on it inside the Problems panel produce the error Unable to open XYZ.cs: File not found.

How can I correctly configure dotnet build or problemMatcher to work?


Solution

  • An easy solution is to let dotnet build produce absolute file path by using /property:GenerateFullPaths=true argument. This is a working task definition:

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