How to configure the executable file name in VS Code? - visual-studio-code

As, my title suggests I want to hard-code my output file name, instead of the default one, where it is named after the file.
This is my tasks.json file in VS Code:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
From this documentation https://code.visualstudio.com/docs/cpp/config-clang-mac, I found a method of doing it, i.e. by replacing "${fileDirname}/${fileBasenameNoExtension}" with a hard-coded filename (for example "${workspaceFolder}/myProgram.out"). But, this is not working for me, I still get the default one. Should I be changing someother configuration along with this?
This executable with file name fills the VS Code Explorer section with repeatitive stuffs and this creates confusion. I found some methods to hide files with certain extensions like .out, .json etc, but the issue is executable file in VS Code(Mac) doesn't have any file extension.

Related

Visual Studio Code User Individual Configuration for Project

I have a project created with defined tasks, for other users to use in my institution.
But now one of my tasks needs a parameter that should be a user defined directory.
How can each user have a configuration file in their project that my tasks can read and get the directory they want the out put to go?
This is a example of my task :
{
"label": "Generate File",
"type": "shell",
"command": "cscript.exe",
"args": [
"//NoLogo",
"${workspaceFolder}/scripts/build.vbs",
"0",
"${output}",
],
"options": {
"cwd": "${workspaceFolder}"
},
The output should be a folder define by each of the users in a configuration or setting file they can put in their project.
Edit :
As Requested i tried to do this
inside my .vscode folder i created a file named settings.json
with this as content
{
"env": {
"dirLoc": "C:\\output\\"
}
}
and tried to use this variable in my tasks.json file
{
"label": "Generate File",
"type": "shell",
"command": "cscript.exe",
"args": [
"//NoLogo",
"${workspaceFolder}/scripts/build.vbs",
"0",
"${env:dirLoc}",
],
"options": {
"cwd": "${workspaceFolder}"
},
but still i did not get anything in the value, it came blank
You can use the extension Command Variable.
It has the command extension.commandvariable.file.content where you can read file content and use it in a variable in the task or launch.
The file can be plain text, key-value, json and yaml.

VS CODE / MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file

I've tried many different ways but I get the error MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file. in Visual Studio code when trying to run my Net Core.
I think I have this configured correctly. The project builds with no errors. I even tried building a new empty project and still get the error.
launch.json
{
// 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": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/API/API/bin/Debug/net5.0/API.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
}
]
}
Tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}

${relativeFileDirname} doesn't resolve in tasks.json

Here's my tasks.json for reference:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "build active file with debug",
"command": "/usr/bin/g++",
"args": [
"${file}",
"-o",
"${workspaceFolder}/out/${relativeFileDirname}.out",
"-g"
],
"problemMatcher": ["$gcc"],
"group": "build",
"detail": "compiler: /usr/bin/g++"
},
]
}
Here's a video to demonstrate the output: https://imgur.com/a/tvurtX1
In the video I am compiling a file 12-how-to-debug-effectively/main.cpp, and according to my tasks.json, the output file should be out/12-how-to-debug-effectively.out, but for some reason the variable substitution doesn't work and I instead get out/.out.
Any pointers where I might be going wrong?
cppbuild is not a valid value for the type argument.
All the examples on the VSC doc site use "type": "shell"
When using "type": "shell" I can see the command to be executed and the variables are filled in correct. (I used a 1 word subdirectory mysite)
Using "type": "cppbuild" I can't see which command is executed.

Problem in VSCode "$gcc" problem matcher to recognize file path in C++ compiler error reports

I have just set my launch.json and tasks.json as the tutorial on the Internet said. But when I pree F5 compile and find some errors, I cannot click the red words "errors" showed in the "Problems".
If I click, the information will be:
Anyone can help me?
task.json
{
// https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
The problem is the "$gcc" problem matcher defined in ms-vscode.cpptools-0.XX.0 extension.
It is the same problem matcher as mentioned in the Task documentation about problem matchers.
This matcher uses relative paths. But MinGW with g++ v8 uses absolute file paths in the error when the source file is supplied with absolute file path in the args property of the task.
Solution is to modify the "$gcc" problem matcher and use absolute file path.
"problemMatcher": {
"base": "$gcc",
"fileLocation": "absolute"
},

Visual Studio Code and GAMS

I have recently discovered that there a gms extension in visual studio code so you can write your GAMS code there. The description of the extension says following:
Provides syntax highlighting for .gms and .inc files and shortcuts for running GAMS models
I wonder if it is possible to actually run your GAMS code from Visual Studio Code?
Yes. You have to do this from the terminal.
You can set up a default build task (shown below) for the current opened file (${fileBasename}) and run with ctrl+shift+b. It's possible to add arguments to the "args" array, i.e. gdx=default etc.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run this file with GAMS",
"type": "shell",
"command": "gams",
"args": [
"${fileBasename}"
],
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"env": {
"PATH": "/opt/gams:${env:PATH}"
}
}
}
]
}