4

I'm a little befuddled that I'm not able to setup Visual Studio Code to do C++ development on Windows using MSVC. All over the web people say how pleased they are with how easy everything is to set up and use, but I don't find any straightforward guides; most of them just skip the setup part and show how nice everything works including code completion/intellisense and debugging support.

I have installed Visual Studio 2015 Community Edition (including the debugging tools etc.), Visual Studio Code and the C++ extension by Microsoft.

What do I need to do next?

Edit: Intellisense works out of the box these days, that's great. But my auto-generated tasks.json doesn't seem to do the trick for building, here's what it looks like:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "build",
            "type": "process",
            "command": "msbuild",
            "args": [
                // Ask msbuild to generate full paths for file names.
                "/property:GenerateFullPaths=true",
                "/t:build"
            ],
            "group": "build",
            "presentation": {
                // Reveal the output only if unrecognized errors occur.
                "reveal": "always"
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
    ]
}

When I run this task it seems to run infinitely and only outputs to the following:

 Executing task: msbuild /property:GenerateFullPaths=true /t:build <

Any ideas?

DenverCoder21
  • 879
  • 3
  • 16
  • 34

2 Answers2

2

For MSVC 2017 version:

  1. add these to your include path:

"D:/Program Files/Microsoft/MSVC2017/VC/Tools/MSVC/14.12.25827/include/*",

"C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt",

"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt/x64",

You may change the drive name and folder name accordingly.

2.change your shell setting in settings.json:

"terminal.integrated.shell.windows": "C:\WINDOWS\System32\cmd.exe", "terminal.integrated.shellArgs.windows": ["/k", "D:/Program Files/Microsoft/MSVC2017/Common7/Tools/VsDevCmd.bat"]

which will enable the cl command in your integrated terminal.

3.Press ctrl+` to enable integrated terminal, type cl /EHsc your_cpp_program.cpp to compile.

JP Zhang
  • 767
  • 1
  • 7
  • 27
1

I think easiest way to get it - open visual studio 2017 command prompt console and run Visual Studio Code IDE from there so it will pick all necessary compiler environment variables

Dev
  • 19
  • 1