Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 734
Bruno Brant Avatar asked Jun 26 '17 12:06

Bruno Brant


1 Answers

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.

like image 97
Jim Griesmer Avatar answered Oct 20 '22 16:10

Jim Griesmer