我使用以下命令创建了一个新的 .NET Core 应用程序:
dotnet new console -o test
当我尝试在 Visual Studio Code 调试器中运行它时,我得到:
Could not find the preLaunchTask 'build'?
Visual Studio Code 为我生成了这些文件:
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(截至本文创建时的最新版本)。
我在 Windows 机器和 Mac 上都尝试过同样的问题。如果我执行命令“dotnet restore”和“dotnet run”,代码运行没有问题,但我仍然收到相同的错误:“找不到 preLaunchTask 'build'”