You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode配置MSVC++2017编译环境求助(tasks.json与c_cpp_properties.json)

Hey there! I totally get where you're coming from—setting up VS Code with different C++ compilers can feel like a rollercoaster, especially when you’ve already had a smooth experience with one toolchain and hit a roadblock with another. Let’s walk through how to configure VS Code to use the Visual Studio 2017 C++ compiler without relying on separate batch files:

Configure VS Code for Visual Studio 2017 C++ Compiler

Prerequisites

  • Make sure you have Visual Studio 2017 installed, with the Desktop development with C++ workload selected during setup. This includes the MSVC compiler, standard libraries, and essential build tools.
  • Note your VS 2017 installation path (default is usually C:\Program Files (x86)\Microsoft Visual Studio\2017\Community—swap Community for Professional or Enterprise if you have those editions).

Step 1: Set Up tasks.json (Build Task)

tasks.json defines how VS Code compiles your code. We can integrate the VS environment setup directly into this file instead of using a batch script:

  1. Open your C++ project folder, press Ctrl+Shift+B, then select Create tasks.json file > Others to use the basic template.
  2. Replace the default content with this configuration (adjust paths to match your VS installation):
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "MSVC 2017 Build",
            "type": "shell",
            "command": "cmd.exe",
            "args": [
                "/C",
                "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat\" x64 && cl /EHsc /Fe:app.exe your_source_file.cpp"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": "$msCompile",
            "detail": "Compiles code using Visual Studio 2017 MSVC compiler"
        }
    ]
}
  • Quick breakdown:
    • cmd.exe /C runs the following command string in a Command Prompt window
    • vcvarsall.bat x64 sets up the 64-bit build environment (use x86 for 32-bit)
    • cl /EHsc /Fe:app.exe your_source_file.cpp is the MSVC compile command: /EHsc enables C++ exception handling, /Fe:app.exe sets the output executable name, and your_source_file.cpp is your main code file (add multiple files here if needed, e.g., file1.cpp file2.cpp)

Step 2: Configure c_cpp_properties.json (IntelliSense)

This file ensures VS Code’s code completion and syntax checking work with MSVC:

  1. Press Ctrl+Shift+P, search for C/C++: Edit Configurations (JSON) to open the file.
  2. Update the content with paths matching your VS 2017 installation (adjust version numbers as needed):
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include",
                "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\ucrt",
                "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\shared",
                "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\um"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\Hostx64\\x64\\cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}
  • Note: The MSVC version number (14.16.27023) and Windows Kits version (10.0.17763.0) may vary on your system—check the actual paths in your VS installation folder to match.

Step 3: Test the Build

  1. Save your source code file (e.g., main.cpp), then press Ctrl+Shift+B to run the build task.
  2. If successful, you’ll find the executable (e.g., app.exe) in your project folder. Run it in the terminal with .\app.exe.

Why This Works Instead of Batch Files

The batch file approach you found likely separated the environment setup and compile command into a separate script. By integrating those steps directly into tasks.json, we eliminate the need for an extra file while achieving the same result—all within VS Code’s built-in task system.

内容的提问来源于stack exchange,提问作者Brian Plummer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:33:02