我已经设法使用官方网站上的教程配置vs代码来构建和运行c ++文件,并且效果很好,但是即使我每次按F5键,它都会重建文件保持不变。
我想要的是运行未更改的文件而不重建它们。 我试图编写另一个任务以“不重新构建即可运行”,但不知道如何在此任务和构建任务之间切换,我在互联网上搜索但没有解决方案。
我的task.json是这样的:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": ["-std=c++11", "starter.cpp"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
和launch.json是:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"cwd": "${workspaceRoot}",
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/mingw64/bin/gdb.exe",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
因此,基本上,“ preLaunchTask”在每次运行时都在运行“ build”任务,但是我想要这样的东西:
if (cpp_file is unchanged) then
"preLaunchTask" : None
else
"preLaunchTask" : "build"
谢谢。
答案 0 :(得分:0)
我所做的是为“运行任务”分配了“ F4”键,然后为“不进行调试”运行分配了“ F5”键,并为“开始调试”分配了“ Ctrl + F5”键组合。
我的task.json:
{
"tasks": [
{
"type": "shell",
"label": "C/C++",
"command": "C:\\Users\\Kamat\\Desktop\\Programacion\\C++\\Compiler\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
我的launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Users\\Kamat\\Desktop\\Programacion\\C++\\Compiler\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Habilitar la impresión con sangría para gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": null
}
]
}
如果您找到一种自动执行此过程的方法,请告诉我,谢谢。
我仍然是一个初学者,我可能会犯一些错误,但这对我来说很有效,我希望它也对您有用。