我使用以下命令创建了一个新的.NET核心应用程序:
dotnet new console -o test当我试图在Visual代码调试器中运行它时,我得到:
Could not find the preLaunchTask 'build'?Visual代码为我生成了这些文件:
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}"
}
]
}我的问题看起来类似于这一个,但在我的例子中,launch.json和tasks.json中的preLaunchTask名称并没有不匹配,所以这个答案不适用于这种情况。我正在运行VisualStudioCodeVersion1.11.2和.NET Core1.1(创建这篇文章时的最新版本)。
我在Windows机器和Mac电脑上都尝试过同样的问题。如果我执行命令"dotnet restore“和"dotnet run",代码运行时不会出现任何问题,但仍然会得到相同的错误:”未能找到preLaunchTask 'build'“
发布于 2018-02-16 04:38:38
更改tasks.json如下。
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"command": "",
"args": [],
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build"
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher": "$msCompile"
}
]
}发布于 2021-06-23 15:31:40
造成此错误的另一个原因可能是,使用的启动配置是在my_project.code-工作区文件(而不是在launch.json文件中)中定义的。
在这种情况下,不使用tasks.json,但任务必须在my_project.code-工作区文件中定义。
这可能是一个“特性”,但它的行为是一个bug,因为:
Configure Task,然后打开或提供创建文件./..vscode/tasks.json如果使用调试配置: my_debug_config (工作区)启动调试会话,则只使用Myproject.code-工作区文件中定义的任务。
但是,在打开相同的工作区时,选择调试配置: dir_debug_config (my_dir),这是在launch.json文件中定义的,然后将使用tasks.json文件中的任务。
发布于 2021-10-22 07:11:59
尝试用绝对路径更改tasks.json和launch.json中的路径。
例如,在launch.json中
"program": "C:/Projects/MyProject/bin/Debug/netcoreapp1.0/XXXX.dll",
"cwd": "C:/Projects/MyProject/"在tasks.json中
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"C:/Projects/MyProject/XXXXXX.csproj"https://stackoverflow.com/questions/43627751
复制相似问题