How to configure VSCode to use Visual C ++ Build Tools for Windows

Using Visual Studio Code and MSFT native C / C ++ extension ( ms-vscode.cpptools

), it is easy to edit C / C ++ on Windows, with good syntax highlighting and incredible intellisense support, no need to install Visual Studio.

With Visual C ++ Build Tools it is possible to do C / C ++ compilations in windows (although, admittedly, the absence make

and necessity of using MSBuild leads to a certain complexity for complex projects).

However, I was unable to configure VSCode to use the command line tools and build tools. Does anyone have a tutorial and know the basic steps to take to achieve easy integration?

Please note that I am asking to use the Visual C ++ Build Tools for Windows.

+3


source to share


1 answer


The fastest and simplest example for a single file-based program is to create a task.json in the folder you 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 will need to change the file from TestFile.cpp to whatever other file or files you have)

Then launch "Developer Command Prompt for VS 2017". From this command window, run the code.exe file. In VS Code, press Ctrl-Shift-B. The file should be compiled successfully. Obviously a lot can be done here. For example, if the open folder contains the msbuild project, you can simply change "command" to "msbuild" and "args" to "myproject.vcxproj". The key point here is that you need to run the code from the developer command line in order to inherit the Build Tools environment.

0


source







All Articles