简体   繁体   中英

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.

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).

However I haven't been able to configure VSCode to use the tools and building means going to the command line. 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.

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:

{
    // 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)

Then run "Developer Command Prompt for VS 2017". From that command window run code.exe. In VS Code, press 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". The key here is that you need to run code from within the developer command-prompt to inherit the Build Tools environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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