Visual Studio Code:找不到 preLaunchTask 'build'? [英] Visual Studio Code: Could not find the preLaunchTask 'build'?

查看:87
本文介绍了Visual Studio Code:找不到 preLaunchTask 'build'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下命令创建了一个新的 .NET Core 应用程序:

I have created a new .NET Core application with the command:

dotnet new console -o test

当我尝试在 Visual Studio Code 调试器中运行它时,我得到:

When I try to run it in the Visual Studio Code debugger, I get:

Could not find the preLaunchTask 'build'?

Visual Studio Code 为我生成了这些文件:

Visual Studio Code generated these files for me:

tasks.json:
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "dotnet",
    "isShellCommand": true,
    "args": [],
    "tasks": [
        {
            "taskName": "build",
            "args": [ ],
            "isBuildCommand": true,
            "showOutput": "silent",
            "problemMatcher": "$msCompile"
        }
    ]
}

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
            "args": [],
            "cwd": "${workspaceRoot}",
            "stopAtEntry": false,
            "console": "internalConsole"
        },
        {
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
            "args": [],
            "cwd": "${workspaceRoot}",
            "stopAtEntry": false,
            "launchBrowser": {
                "enabled": true,
                "args": "${auto-detect-url}",
                "windows": {
                    "command": "cmd.exe",
                    "args": "/C start ${auto-detect-url}"
                },
                "osx": {
                    "command": "open"
                },
                "linux": {
                    "command": "xdg-open"
                }
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceRoot}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

我的问题看起来类似于这个,但在我的如果 preLaunchTask 的 launch.json 和 tasks.json 中的名称没有不匹配,则答案在这种情况下不适用.我正在运行 Visual Studio Code 1.11.2 版和 .NET Core 1.1(截至本文创建时的最新版本).

My problem looks similar to this one, but in my case there are no mismatches between the names in launch.json and tasks.json for the preLaunchTask so the answer does not apply in this case. I'm running Visual Studio Code version 1.11.2 and .NET Core 1.1 (latest versions as of when this post was created).

我在 Windows 机器和 Mac 上都试过同样的问题.如果我执行命令dotnet restore"和dotnet run",代码运行没有问题,但我仍然收到相同的错误:找不到 preLaunchTask 'build'"

I have tried the same on both a Windows machine and a Mac with the same problem. If I do the command "dotnet restore" and "dotnet run", the code runs with no problems, but I still get the same error: "Could not find the preLaunchTask 'build'"

推荐答案

对我来说,它可以在 tasks.json 和/或 launch.json 之后重新启动 VS Code文件创建.

For me, it works to restart VS Code after tasks.json and/or launch.json files creation.

另请注意,您需要使用 dll 路径更新 launch.json 中的 "program" 设置.

Also note, that you need to update "program" settings in launch.json with the path to dlls.

这篇关于Visual Studio Code:找不到 preLaunchTask 'build'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆