Windows 10下vscode使用visual studio 2019的MSVC配置C/C++编译环境

准备

vscode (安装了从C/C++扩展)
安装了visual studio 2019(安装vc++组件)

配置步骤

第一步从visual studio 打开vscode

按win键,搜索
Windows 10下vscode使用visual studio 2019的MSVC配置C/C++编译环境_第1张图片然后cd 到你的项目文件目录,敲一下code .

第二步配置tasks.json

{
  "version": "2.0.0",
  "windows": {
    "options": {
      "shell": {
        "executable": "cmd.exe",
        "args": [
          "/C",
          // The path to VsDevCmd.bat depends on the version of Visual Studio you have installed.
          "\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/Tools/VsDevCmd.bat\"",
          "&&"
        ]
      }
    }
  },
  "tasks": [
    {
      "type": "shell",
      "label": "cl.exe build active file",
      "command": "cl.exe",
      "args": [
        "/Zi",
        "/EHsc",
        "/Fe:",
        "${fileDirname}\\${fileBasenameNoExtension}.exe",
        "${file}"
      ],
      "problemMatcher": ["$msCompile"],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    },
    {
      "type": "shell",
      "label": "delete extra files",
      "command": "${fileDirname}/hello.bat"
    }
  ]
}

如果你的是visual studio 2019 profession的话,那就直接用就行了,否则改下VsDevCmd.bat的路径
hello.bat

@echo off
set path=%fileDirname%
for /r %path% %%s in (*.exe *.ilK *.obj *.pdb) do (
    del /f /s /q "%%s"
)

hello.bat 放在工作目录下

Windows 10下vscode使用visual studio 2019的MSVC配置C/C++编译环境_第2张图片我配置好了一份
链接:https://pan.baidu.com/s/1j34p_MU0jGQUCp1kNWt5QQ
提取码:uexd
–来自百度网盘超级会员V3的分享

你可能感兴趣的:(笔记,vscode,c++,visual,studio)