2017-04-26 67 views
10

我已经创建了命令一个新的.NET核心应用:Visual Studio代码:无法找到preLaunchTask'build'?

dotnet new console -o test 

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

Could not find the preLaunchTask 'build'? 

Visual Studio代码生成这些对我来说文件:

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}" 
     } 
    ] 
} 

我的问题看起来类似于this one,但在我的情况下,launch.json和tasks.json中的名称对于preLaunchTask没有不匹配,所以在这种情况下,答案不适用。我正在运行Visual Studio Code版本1.11.2和.NET Core 1.1(创建此帖子时的最新版本)。

我在Windows计算机和Mac上都尝试了相同的问题。如果我执行命令“dotnet restore”和“dotnet run”,代码运行没有问题,但我仍然得到相同的错误:“找不到preLaunchTask'内部版本'”

+0

任何解决方案@OlavT –

+0

https://github.com/Microsoft/vscode/issues/22250 –

+0

我认为,发射前的任务只有在tasks.json设置为2.0.0版本的作品。看看jagadeesh提供的样品。 – Jon

回答

10

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

另请注意,您需要更新launch.json中的"program"设置,并指定dll的路径。

+0

由于重新启动VS Code让我过去了这个问题。但是,现在它抱怨这样的问题:“预定义类型'System.Object'没有定义或导入...”VS代码是否也提示从VS代码执行“dotnet恢复”?我想我以前见过。 – OlavT

+0

一般来说,它应该。不知道现在VS代码决定何时显示该提示。无论如何,你总是可以从VS Code内的终端手动执行'dotnet restore'。 – Set

+0

我也记不起我必须手动设置程序的路径才能在launch.json文件中进行调试。 VS Code为什么不能做幕后花招?它应该知道在哪里可以找到可执行文件而不涉及用户? – OlavT

0

并将在下一个版本中提供。重新打开VS代码文件夹应该有助于解决问题。

+2

我有最新版本,仍然有同样的问题。我是否必须手动创建'tasks.json'文件?一个似乎不会自动创建。 – melston

0

更改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" 
     } 
    ] 
} 
相关问题