简体   繁体   English

如何设置VSCode以使用Visual C ++ Build Tools for Windows

[英]How to setup VSCode to use Visual C++ Build Tools for Windows

Using Visual Studio Code and MSFT own C/C++ extension ( ms-vscode.cpptools ), one can edit C/C++ easily within Windows, with good syntax highlight and incredible intellisense support, without the need to install Visual Studio. 使用Visual Studio Code和MSFT自己的C / C ++扩展( ms-vscode.cpptools ),可以在Windows中轻松编辑C / C ++,具有良好的语法突出显示和令人难以置信的智能感知支持,而无需安装Visual Studio。

Using Visual C++ Build Tools, one can do C/C++ compilations within windows (although, admittedly, the absence of make and the need to use MSBuild results in a certain difficulty for complex projects). 使用Visual C ++构建工具,可以在Windows中进行C / C ++编译(尽管如此,没有make和使用MSBuild的需要导致复杂项目的某些困难)。

However I haven't been able to configure VSCode to use the tools and building means going to the command line. 但是,我无法配置VSCode以使用工具和构建方法转到命令行。 Does anyone have a tutorial and know the main steps to take in order to achieve a simple integration? 有没有人有一个教程,并知道要实现简单集成的主要步骤?

Please note that I'm asking about using Visual C++ Build Tools for Windows. 请注意,我问的是使用Visual C ++ Build Tools for Windows。

The quickest, simplest case for a one file program is to create a tasks.json in the folder you have opened that looks like this: 一个文件程序最快,最简单的情况是在你打开的文件夹中创建一个tasks.json,如下所示:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "compile",
            "type": "shell",
            "command": "cl",
            "args": [
                "TestFile.cpp"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

(Of course you'd need to change the file from TestFile.cpp to whatever other file or files you may have) (当然,您需要将文件从TestFile.cpp更改为您可能拥有的任何其他文件)

Then run "Developer Command Prompt for VS 2017". 然后运行“VS 2017的开发人员命令提示符”。 From that command window run code.exe. 从该命令窗口运行code.exe。 In VS Code, press Ctrl-Shift-B. 在VS Code中,按Ctrl-Shift-B。 The file should be compiled successfully. 该文件应该成功编译。 There is obviously much more that could be done here. 显然,这里可以做得更多。 For example, if the folder you have open contains an msbuild project, you could just change "command" to "msbuild" and "args" to "myproject.vcxproj". 例如,如果您打开的文件夹包含msbuild项目,则可以将“command”更改为“msbuild”,将“args”更改为“myproject.vcxproj”。 The key here is that you need to run code from within the developer command-prompt to inherit the Build Tools environment. 这里的关键是您需要在开发人员命令提示符下运行代码以继承Build Tools环境。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM