【问题标题】:Auto run executable after save in Visual Studio Code在 Visual Studio Code 中保存后自动运行可执行文件
【发布时间】:2016-09-03 07:52:22
【问题描述】:

我想使用 Visual Studio 代码进行 C 编程,我想自动化保存 -> 编译 -> 运行的过程。目前我已经安装了 MinGW 并使用 C/C++ 扩展,我使用 Ctrl+S 实现了保存和编译(我更改了编译的快捷方式),但为了执行,我需要转到 cmd 提示符并执行程序。

有什么方法可以使用一个按钮来实现吗?

【问题讨论】:

  • 如果它对你来说真的那么重要,你为什么不买一个像MSVS ExpressEclipse/CDT这样的全功能IDE?
  • Visual Studio 重而日食?不...

标签: c visual-studio-code


【解决方案1】:

我最接近的方法是定义我的快捷方式

[
   {
       "key": "ctrl+s",          
       "command": "workbench.action.tasks.build" 
   },
   {
       "key": "ctrl+d",          
       "command": "workbench.action.tasks.test" 
   }
]

然后在tasks.json中

{
   "version": "0.1.0",
   "command": "cmd",
   "isShellCommand": true,
   "args": ["/C"],
   "showOutput": "silent",
   "tasks": [
       {
           "taskName": "saveNcompile",
           "suppressTaskName": true,
           "isBuildCommand": true,
           "args": ["gcc main.c -o main.exe"]
       }, {
           "taskName": "execute",
           "suppressTaskName": true,
           "isTestCommand": true,
           "args": ["main.exe"]
       }
   ]
}

现在使用 ctrl+s 保存并编译并 ctrl+d 执行。

【讨论】:

  • 请告诉我在哪里存储第一个文件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-14
  • 2019-07-17
相关资源
最近更新 更多