0

I've created an ASP.NET Core app with Angular from the console (dotnet new angular command). I want to enable debugging in Visual Studio Code for this application. I go to the Debug tab, click on the cog and create the launch.json file from the .NET Core template. If I press F5 to debug there comes to an error "Could not find the preLaunchTask 'build'". On Internet, I read that I should press Configure Task button and then select .NET Core option to create correct tasks.json file but this option is missing, there are only options for npm and tsc. How can I fix that? Is this possible with the angular template?

Roman Suska
  • 527
  • 2
  • 7
  • 21
  • have you tried to restart VS Code? SO [Visual Studio Code: Could not find the preLaunchTask 'build'?](https://stackoverflow.com/questions/43627751/visual-studio-code-could-not-find-the-prelaunchtask-build/43635509#43635509) – Set Oct 15 '17 at 21:08

2 Answers2

1

Here is what worked for me for .NET Core 2.0:

  1. Check if you have .NET Core SDK 2.0 or later
  2. Check if you have C# extension from VS Code. If not install from marketplace
  3. Install Node
  4. Create project using 'dotnet new angular'
  5. create tasks.json file if VSCode hasn't done that already. File should be located in same folder as launch.json (it should be '.vscode' folder) enter image description here
  6. Content of tasks.json:
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "npm",
            "script": "install",
            "problemMatcher": []
        },
        {
            "taskName": "build",
            "command": "dotnet",
            "args": [
            "build"
            ],
            "options": {
                "cwd": "${workspaceRoot}"
                },
                "isBuildCommand": true,
                "showOutput": "always",
                "problemMatcher": "$msCompile"
                }
    ]
}
  1. Run debug!
Ivan Milosavljevic
  • 839
  • 1
  • 7
  • 19
  • The key takeaway from this answer is to install the C# extension. Afterward, whenever you open a new project it will prompt you with a message like so: Required assets to build and debug are missing from 'angular'. Add them? If you clicked the 'Yes' button, the two files will be created for you: .vscode/launch.json & .vscode/tasks.json. – Stephen Pham Dec 30 '18 at 05:58
0

A more relevant option for 2022 is (it still may require some editing due to specific things in your project):

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/MyWebApp.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish",
            "command": "dotnet",
            "type": "process",
            "args": [
                "publish",
                "${workspaceFolder}/MyWebApp.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "watch",
            "command": "dotnet",
            "type": "process",
            "args": [
                "watch",
                "run",
                "${workspaceFolder}/MyWebApp.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}
Ustin
  • 568
  • 6
  • 19