Tôi đã tạo ra một ứng dụng .NET Core mới với lệnh:Visual Studio Code: Không thể tìm thấy preLaunchTask 'build'?
dotnet new console -o test
Khi tôi cố gắng chạy nó trong trình gỡ lỗi Visual Studio Mã, tôi nhận được:
Could not find the preLaunchTask 'build'?
Visual Studio Mã tạo ra những file cho tôi:
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"
}
]
}
và
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}"
}
]
}
Vấn đề của tôi trông giống như this one, nhưng trong trường hợp của tôi không có sự không khớp giữa các tên trong tệp launch.json và tasks.json cho preLaunchTask để câu trả lời không áp dụng trong trường hợp này. Tôi đang chạy Visual Studio Code phiên bản 1.11.2 và .NET Core 1.1 (phiên bản mới nhất kể từ khi bài đăng này được tạo).
Tôi đã thử tương tự trên cả máy tính Windows và máy Mac có cùng sự cố. Nếu tôi thực hiện lệnh "dotnet restore" và "dotnet run", mã chạy không có vấn đề gì, nhưng tôi vẫn gặp lỗi tương tự: "Không thể tìm thấy preLaunchTask 'build'"
bất kỳ giải pháp @OlavT –
https://github.com/Microsoft/vscode/issues/22250 –
Tôi nghĩ rằng nhiệm vụ prelaunch chỉ làm việc với phiên bản thiết lập để 2.0.0 trong tasks.json. có một cái nhìn tại các mẫu được cung cấp bởi jagadeesh. – Jon