Creating a Clean Task for .Net Core Projects in VS Code
By Harry Bellamy
- 1 minutes read - 210 wordsWhen you create or open a .Net Core project in VS Code, it gives you the option to create the necessary files for building the project.
One of the files created in this process is tasks.json
.
What tasks.json
defines is a series of named tasks that perform a series of actions on the project (e.g. build, publish, etc…).
One task that isn’t defined by default is a clean task. A clean task is often useful if your project is not building for strange and/or unknown reasons - sometimes these issues can be caused by the intermediate build files that are not recreated from repeated builds. A clean task will remove these files, which will get recreated during the next build.
To add a clean task, add the following JSON snippet to the tasks array in your tasks.json
:
{
"label": "clean",
"command": "dotnet",
"type": "process",
"args": [
"clean",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
This tasks runs dotnet clean
to clean build output of all projects/a solution.
You can then run this task in one of two ways:
- From the Run menu select
Run Task
and selectclean
from the list. - Hit
Ctrl+Shift+p
to open the Command Palette and entertasks
. Then selectTasks: Run Task
and selectclean
from the list.