VS代码:在构建任务之前设置MSVC环境

时间:2020-02-09 19:01:45

标签: visual-c++ visual-studio-code vscode-settings vscode-tasks

要在VSCode中使用MSVC编译器构建项目,必须从开发人员控制台运行VSCode。 微软公司在VSCode(https://code.visualstudio.com/docs/cpp/config-msvc)上的文档告诉我们。否则,任何运行这样的简单构建任务(请参见下文)的方法都将返回简单的““ cl.exe”不是内部程序还是外部程序...“

{
        "label": "msvc build",
        "type": "shell",
        "command": "cl.exe",
        "args": ["/EHsc", "/Zi", "/Fe:", "test.exe", "test.cpp"]
}

但是我们可以使用vsvarsall.bat手工准备外壳。

  {
    "label": "Setup MSVC 140 params (VS2015)",
    "type": "shell",
    "command":["c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/vcvarsall.bat", "x64","10.0.18362.0" ,"-vcvars_ver=14.0"],
    "group":"build"
  }

阅读有关任务的文档,我们看到“ dependsOn”选项。(https://code.visualstudio.com/docs/editor/tasks

{
        "label": "msvc build",
        "type": "shell",
        "command": "cl.exe",
        "args": ["/EHsc", "/Zi", "/Fe:", "test.exe", "test.cpp"],
        "dependsOrder": "sequence",
        "dependsOn":["Setup MSVC 140 params"],
}

仍然““ cl.exe”不是内部程序或外部程序...“。 所以...我如何运行vcvarsall,并使用VSCode任务在同一shell cl中运行它?最好不要使用带有单独批处理文件(如here)的恶作剧。

0 个答案:

没有答案