'Couldn't add .NET Core tasks.json in VSCode
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?
Solution 1:[1]
Here is what worked for me for .NET Core 2.0:
- Check if you have .NET Core SDK 2.0 or later
- Check if you have C# extension from VS Code. If not install from marketplace
- Install Node
- Create project using 'dotnet new angular'
- 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)
- 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"
}
]
}
- Run debug!
Solution 2:[2]
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"
}
]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ivan Milosavljevic |
Solution 2 | Ustin |