How to set a task as the build task? - visual-studio-code

I am attempting to run a helloworld C++ program in VSCode. This code is running inside a C++ docker container using dev containers extension. I have created the following tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "CPP build",
"type": "cppbuild",
"command": "g++ helloworld.cpp -o helloworld"
}
]
}
Then I run command+shift-B or terminal run build task. I get the following error:
No build task to run found. Configure Build Task...
Furthermore, a warning pops up in the lower right that says, "There are task errors. See the output for details" When I click on this it says:
Error: The cppbuild task detection didn't contribute a task for the following configuration:
{
"label": "CPP build",
"type": "cppbuild",
"command": "g++ helloworld.cpp -o helloworld"
}
How do I set this task as my build task so that I can build it?

Related

What is the flutter command to clear app data?

Sometimes we need to run app by clearing app data and cache. It is a hassle to do it manually every time going to setting screens.I saw maximum stack-overflow answers recommending it programmatically but I don't need it. Is there any flutter command or plugin to do that?
There is actually no flutter command to clear app data.
However, you could use prelaunch tasks to run shell command before launching your app.
You must have adb command in your environment PATH variable for Android apps
For example, in VsCode, you can add a task in the tasks.json file like this :
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "clear app data",
"type": "shell",
"command": "adb shell pm clear com.package.app || true;xcrun simctl uninstall booted com.package.app",
"problemMatcher": []
}
]
}
Then, add the preLaunchTask in your launch.json file like this :
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "my_app",
"request": "launch",
"type": "dart",
"program": "lib/main.dart",
"preLaunchTask": "clear app data",
}
]
}
I don't know how to do this in IntelliJ but I'm sure you can do the same thing

how to fix gst/gst.h not found on Visual studio code running on UBUNTU

On the terminal we can use 'pkg-config --cflags --libs gstreamer-1.0' along with gcc <file.c> -o to complile the gstreamer application and avoid gst/gst.h not found error.
I am using ubuntu 18.04 to run the test application. I use VS Code remote ssh to edit the code on Ubuntu. But I am not able to build or debug the code because of this error.
enter image description here
Is there a way to tell VS code to compile with this pkg-config --cflags --libs gstreamer-1.0 flag.
Or is there a way to tell gcc to automatically look for gst.h in gstreamer libraries.
I am new to this, I enjoy using VS Code, and dont want to switch back and froth from the terminal.
To solve editor include error, add this to your Include path:
${workspaceFolder}/*
/usr/include/gstreamer-1.0/*
It works for current latest Visual Code (version 1.71.2). Pay attention to one asterisk character only
To solve compilation error, add this for your task.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc-9 build active file",
"command": "/usr/bin/gcc-9",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
**"`pkg-config --cflags --libs gstreamer-1.0`"**
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}

How to run multiple tasks upon launch in vscode?

I have the following launch task in launch.json:
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/MyProject.dll",
[...]
I would also like to run npm run start:dev, when launching, and terminate it when stopping. So I added this:
{
"command": "npm run start:dev",
"name": "Run npm start:dev",
"request": "launch",
"type": "node-terminal",
"cwd": "${workspaceFolder}/ClientApp",
}
But the latter doesn't do anything. Is it possible to run npm run start:dev upon launch together with an MVC Core app?

VSCode - how to keybind an external command

Im trying to run "puppet-lint -f (currently open file)
The Puppet extenstion provides puppet-lint check, but doesnt auto fix any issues, it just gives warnings. How can I add a keyboard shortcut to run "puppet-lint -f" on a file Im currently editing?
Thanks
I don't know anything about the Puppet extension but in general here is how you can bind a shell command to a keychord:
Make a task for it (.vscode/tasks.json):
{
"version": "2.0.0",
"tasks": [{
"label": "node version",
"command": "node",
"args": [
"-v"
],
"type": "shell"
}]
}
In the args you may use ${file} for the current file.
Then add this option to your keybindings.json (you can find them in Command Palette under “Preferences: Open keyboard shortcuts (JSON)”):
{
"key": "shift+escape",
"command": "workbench.action.tasks.runTask",
"args": "node version"
},
co-author of the extension here. You can have the Puppet VSCode Extension run puppet-lint fix on the current file by using the Format Document command. You can then configure VSCode to run format on save.

Use Visual Studio Code Tasks with Gulp 4.0

I am in the process of switching a project from Gulp 3.9.1 (npm install gulp) to Gulp 4.0 (npm install gulp-4.0.build), but when I do this, Visual Studio Code is no longer able to auto-detect the tasks in my gulpfile.js. In both cases, gulp is installed locally.
My .vscode/tasks.json looks like:
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"showOutput": "always"
}
Looking at the Tasks output, I see the following message:
Running gulp --tasks-simple didn't list any tasks. Did you run npm install?
Can you use Gulp 4.0 with VS Code and have it autodetect the tasks? If so, what steps do I need to follow to get it setup?
Yes, you can use vscode and gulp4.0. I would look at how to upgrade to gulp4.0.
Did you uninstall gulp3.9.1 first?
You should also install gulp4.0 both locally and globally!
Then run
gulp -v
to make sure it worked. vsCode should detect both tasks in your tasks.json file and from your gulpfile.js. You are using the older tasks.json version 0.1.0. Here is an example of a tasks.json file which allows me to type "gulp sync" in the command line from anywhere in the workspaceRoot and run that task:
{
"version": "2.0.0",
"tasks": [
{
"label": "Start server and process files",
"command": "gulp",
"args": [
"sync"
],
"type": "shell",
"options": {
"cwd": "${workspaceRoot}"
}
}
]
}
It runs the "sync" task I defined in my gulpfile.js. In fact you can assign a hotkey combo to that such as:
{ "key": "shift+escape",
"command": "workbench.action.tasks.runTask",
"args": "Start server and process files"
},
in your keybindings.json.