Could not find the preLaunch task 'build'

前端 未结 4 2080
死守一世寂寞
死守一世寂寞 2020-12-14 06:05

To configure Visual Studio Code to debug C# scripts on OSX, I followed through all the steps listed in the article below:

Debugging C# on OSX with Visual Studio Cod

相关标签:
4条回答
  • 2020-12-14 06:40

    You can use the Visual Studio Code to solve it.

    When you see the error message, click on the steps below

    1. Configure Task
    2. Create tasks.json file from template
    3. NET Core Executes .NET Core build commands

    The VSCode will create a file like it:

    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "command": "dotnet build",
                "type": "shell",
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    

    It's finished. The VSCode will build the project before run.

    0 讨论(0)
  • 2020-12-14 06:42

    It seems like this will be different for every scenario.

    For me what @Jeferson Tenorio worked, but it needed a few more steps so let's add them:

    1. Click on Configure Task:
    2. Create tasks.json file from template
    3. .NET Core Executes .NET Core build commands
    4. Go to your launch.json file, and under configurations/program you will find this:

      ${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll

      Simply replace <insert-target-framework-here> and <insert-project-name-here> with your target framework, in my case that would be netcoreapp2.0 and then your project name (if you haven't changed anything your project name should be the same as the folder where you created your project), it should look something like this:

      "program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/MyProject.dll"

      I hope this helps.

    0 讨论(0)
  • 2020-12-14 06:50

    The error occurs because Visual Studio Code cannot find any task in the tasks.json with the taskName value set to 'build'.

    The preLaunchTask property of the launch.json file defines the task that should be executed before the script is launched. From the question, Visual Studio Code has been configured to run the task build before launching the script:

    preLaunchTask: 'build'
    

    But there's no task named 'build' in the tasks.json file.

    To fix this, you should change the value of the preLaunchTask property to 'exe', which is the build task that has been defined in the tasks.json file.

    0 讨论(0)
  • 2020-12-14 06:53

    On Linux, to get the build command to work, I needed to change the tasks.json file from:

    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "command": "dotnet build",
                "type": "shell",
                "args": [
                    // Ask dotnet build to generate full paths for file names.
                    "/property:GenerateFullPaths=true",
                    // Do not generate summary otherwise it leads to duplicate errors in Problems panel
                    "/consoleloggerparameters:NoSummary"
                ],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    

    to:

    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "command": "dotnet",
                "type": "shell",
                "args": [
                    "build"
                    // Ask dotnet build to generate full paths for file names.
                    "/property:GenerateFullPaths=true",
                    // Do not generate summary otherwise it leads to duplicate errors in Problems panel
                    "/consoleloggerparameters:NoSummary"
                ],
                "group": "build",
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
    

    the reason for this is the fact that Linux will treat the task generated by VSC as running command "dotnet build" instead of "dotnet" with the parameter of "build". Without the change you will receive "dotnet build: command not found" with exit code 127

    0 讨论(0)
提交回复
热议问题