You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Visual Studio 2017 and later, the "Open Folder" feature enables you to open a folder of source files and immediately start coding with support for IntelliSense, browsing, refactoring, debugging, and so on. No .sln or .vcxproj files are loaded; if needed, you can specify custom tasks as well as build and launch parameters through simple .json files. For general information about Open Folder, see [Develop code in Visual Studio without projects or solutions](/visualstudio/ide/develop-code-in-visual-studio-without-projects-or-solutions).
9
+
In Visual Studio 2017 and later, the "Open Folder" feature enables you to open a folder of source files and immediately start coding with support for IntelliSense, browsing, refactoring, debugging, and so on. As you edit, create, move, or delete files, Visual Studio tracks the changes automatically and continuously updates its IntelliSense index. No .sln or .vcxproj files are loaded; if needed, you can specify custom tasks as well as build and launch parameters through simple .json files. For general information about Open Folder, see [Develop code in Visual Studio without projects or solutions](/visualstudio/ide/develop-code-in-visual-studio-without-projects-or-solutions).
10
10
11
-
CMake is integrated in the Visual Studio IDE as a component of the C++ desktop workload. For more information, see [CMake projects in Visual Studio](cmake-projects-in-visual-studio.md). For any other build system, you can use the Open Folder feature. Open Folder effectively decouples the code editor, debugger and analyzers from the build system and the compiler toolset. You can use the C++ code editor with its rich IntelliSense features, the code analyzers, and the Visual Studio debugger with virtually any build system, including CMake, Ninja, QMake (for Qt projects), gyp, SCons, Gradle, Buck, make and more. It even works with a single file or a loose collection of files with no build system.
11
+
## CMake and Qt
12
12
13
-
To use Open Folder, from the main menu select **File | Open | Folder** or press **Ctrl + Shift + Alt + O**.
14
-
Solution Explorer immediately displays all the files in the folder. You can click on any file to begin editing it. In the background, Visual Studio starts indexing the files to enable IntelliSense, navigation, and refactoring features. As you edit, create, move, or delete files, Visual Studio tracks the changes automatically and continuously updates its IntelliSense index.
13
+
CMake is integrated in the Visual Studio IDE as a component of the C++ desktop workload. The workflow for CMake is not identical to the workflow described in this article. If you are using CMake, see [CMake projects in Visual Studio](cmake-projects-in-visual-studio.md). You can also use CMake to build Qt projects, or you can use the [Qt Visual Studio Extension](https://download.qt.io/development_releases/vsaddin/) for either Visual Studio 2015 or Visual Studio 2017.
15
14
16
-
## QMake projects that target the Qt framework
15
+
## Other build systems
17
16
18
-
You can use CMake to build Qt projects, or you can use the [Qt Visual Studio Extension](https://download.qt.io/development_releases/vsaddin/) for either Visual Studio 2015 or Visual Studio 2017.
19
-
20
-
## gyp, Cons, SCons, Buck, etc
21
-
22
-
You can use any build system in Visual Studio and still enjoy the advantages of the C++ IDE and debugger. When you open the root folder of your project, the C++ code editor uses heuristics to index the source files for IntelliSense and browsing. You can provide hints about the structure of your code by editing the CppProperties.json file. In a similar way, you can configure and invoke your build program by editing the launch.vs.json file.
23
-
24
-
## Configuring Open Folder projects
25
-
26
-
You can customize an Open Folder project through three JSON files:
17
+
To use the Visual Studio IDE with a build system or compiler toolset that is not directly supported (for example, make, gyp, SCons, Gradle, Buck, and so on), from the main menu select **File | Open | Folder** or press **Ctrl + Shift + Alt + O**. Navigate to the folder that contains your source code files. To build the project, define custom tasks, or configure IntelliSense for system headers, you add three JSON files:
27
18
28
19
|||
29
20
|-|-|
30
21
|CppProperties.json|Specify custom configuration information for browsing. Create this file, if needed, in your root project folder. (Not used in CMake projects.)|
31
-
|tasks.vs.json|Specify custom build commands and compiler switches. Accessed via the **Solution Explorer** context menu item **Configure Tasks**.|
32
-
|launch.vs.json|Specify command line arguments for the debugger. Accessed via the **Solution Explorer** context menu item **Debug and Launch Settings**.|
22
+
|tasks.vs.json|Specify custom build commands. Accessed via the **Solution Explorer** context menu item **Configure Tasks**.|
23
+
|launch.vs.json|Specify command line arguments for the debugger. Accessed via the **Solution Explorer** context menu item **Debug and Launch Settings**.|
33
24
34
25
### Configure IntelliSense and browsing hints with CppProperties.json
35
26
36
-
IntelliSense and browsing behavior partly depends on the active build configuration, which defines #include paths, compiler switches, and other parameters. By default, Visual Studio provides Debug and Release configurations. CMake projects use the CMakeSettings.json file and CMakeLists.txt files for this purpose. For other kinds of Open Folder projects, you may need to create a custom configuration in order for IntelliSense and browsing features to fully comprehend your code. To define a new configuration, create a file called CppProperties.json in the root folder. Here is an example:
27
+
For IntelliSense and browsing behavior such as **Go to Definition** to work correctly, Visual Studio needs to know which compiler you are using, where the system headers are, and where any additional include files are located if they are not directly in the folder you have opened (the workspace folder). To specify a configuration, you can choose **Manage Congfigurations** from the dropdown in the main toolbar:
If, for example, you choose **x64-Debug**, Visual Studio creates a file called `CppProperties.json` in your root project folder and populates it like so:
37
36
38
37
```json
39
38
{
40
39
"configurations": [
41
40
{
42
-
"name": "Windows x64",
43
-
"includePath": [ "include" ],
44
-
"defines": [ "_DEBUG" ],
45
-
"compilerSwitches": "/std:c++17",
46
-
"intelliSenseMode": "windows-msvc-x64",
47
-
"forcedInclude": [ "pch.h" ],
48
-
"undefines": []
41
+
"inheritEnvironments": [
42
+
"msvc_x64"
43
+
],
44
+
"name": "x64-Debug",
45
+
"includePath": [
46
+
"${env.INCLUDE}",
47
+
"${workspaceRoot}\\**"
48
+
],
49
+
"defines": [
50
+
"WIN32",
51
+
"_DEBUG",
52
+
"UNICODE",
53
+
"_UNICODE"
54
+
],
55
+
"intelliSenseMode": "windows-msvc-x64"
49
56
}
50
57
]
51
58
}
52
59
```
53
-
For more information, see [CppProperties schema reference](cppproperties-schema-reference.md).
60
+
61
+
This configuration "inherits" the environment variables of the Visual Studio [x64 Developer Command Prompt](building-on-the-command-line.md). One of those variables is `INCLUDE` and you can refer to it here by using the `${env.INCLUDE}` macro. The `includePath` property tells Visual Studio where to look for all the sources that it needs for IntelliSense. In this case, it says "look in the all the directories specified by the INCLUDE environment variable, and also all the directories in the current working folder tree. The `name` property is the name that will appear in the dropdown, and can be anything you like. The `defines` property provides hints to IntelliSense when it encounters conditional compilation blocks. The `intelliSenseMode` property provides some additional hints based on the compiler type. Several options are available for MSVC, GCC, and Clang.
62
+
63
+
If you are using a different compiler, you have to create a custom configuration and environment in *cppproperties.json*. The following example shows a complete *cppproperties.json* file with a single custom configuration for using GCC in an MSYS2 installation:
Note the `environments` block. It defines properties that behave like environment variables and are available not only in the *cppproperties.json* file, but also in the other configuration files *task.vs.json* and *launch.vs.json*. The `Mingw64` configuration inherits the `mingw_w64` environment, and uses its INCLUDE property to specify the value for `includePath`. You can add other paths to this array property as needed.
94
+
95
+
The `intelliSenseMode` property is set to a value appropriate for GCC. For more information on all these properties, see [CppProperties schema reference](cppproperties-schema-reference.md).
96
+
97
+
When everything is working correctly, you will see IntelliSense from the GCC headers when you hover over a type:
98
+
99
+

100
+
101
+
If you are not seeing the IntelliSense that you expect, you can troubleshoot by going to **Tools** > **Options** > **Text Editor** > **C/C++** > **Advanced** and setting **Enable Logging** to **true**. To start with, try setting **Logging Level** to 5, and **Logging Filters** to 8.
Output is piped to the **Output Window** and is visible when you choose **Show Output From: Visual C++ Log*. The output contains, among other things, the list of actual include paths that IntelliSense is trying to use.
106
+
107
+
> [!WARNING]
108
+
> There is currently a known issue in which the `INCLUDE` value specified in `environments` is not correctly passed to the `includePath` property. You can work around the issue by adding the complete literal include paths to the `includePath` array.
54
109
55
110
### Define build tasks with tasks.vs.json
56
111
57
112
You can automate build scripts or any other external operations on the files you have in your current workspace by running them as tasks directly in the IDE. You can configure a new task by right-clicking on a file or folder and selecting **Configure Tasks**.
This creates (or opens) the **tasks.vs.json** file in the .vs folder which Visual Studio creates in your root project folder. You can define any arbitrary task in this file and then invoke it from the **Solution Explorer** context menu. The following example shows a tasks.vs.json file that defines a single task. `taskName` defines the name that appears in the context menu. `appliesTo` defines which files the command can be performed on. The `command` property refers to the COMSPEC environment variable, which identifies the path for the console (cmd.exe on Windows). You can also reference environment variables that are declared in CppProperties.json or CMakeSettings.json. The `args` property specifies the command line to be invoked. The `${file}` macro retrieves the selected file in **Solution Explorer**. The following example will display the filename of the currently selected .cpp file.
116
+
This creates (or opens) the *tasks.vs.json* file in the .vs folder which Visual Studio creates in your root project folder. You can define any arbitrary task in this file and then invoke it from the **Solution Explorer** context menu. To continue with the GCC example, the following example shows a complete *tasks.vs.json* file with as single task that invokes *g++.exe* to build a project. Assume the project contains a single file called *hello.cpp*.
117
+
118
+
```json
119
+
{
120
+
"version": "0.2.1",
121
+
"tasks": [
122
+
{
123
+
"taskLabel": "build hello",
124
+
"appliesTo": "/",
125
+
"type": "default",
126
+
"command": "g++",
127
+
"args": [
128
+
"-g",
129
+
"-o",
130
+
"hello",
131
+
"hello.cpp"
132
+
]
133
+
}
134
+
]
135
+
}
136
+
137
+
```
138
+
139
+
You can now run this task by right-clicking on the project node in **Solution Explorer** and choosing **build hello**. When the task completes you should see a new file, *hello.exe* in **Solution Explorer**.
140
+
141
+
You can define many kinds of tasks. The following example shows a tasks.vs.json file that defines a single task. `taskName` defines the name that appears in the context menu. `appliesTo` defines which files the command can be performed on. The `command` property refers to the COMSPEC environment variable, which identifies the path for the console (*cmd.exe* on Windows). You can also reference environment variables that are declared in CppProperties.json or CMakeSettings.json. The `args` property specifies the command line to be invoked. The `${file}` macro retrieves the selected file in **Solution Explorer**. The following example will display the filename of the currently selected .cpp file.
62
142
63
143
```json
64
144
{
@@ -81,9 +161,36 @@ For more information, see [Tasks.vs.json schema reference](tasks-vs-json-schema-
81
161
82
162
### Configure debugging parameters with launch.vs.json
83
163
84
-
To customize your program’s command line arguments, right-click on the executable in **Solution Explorer** and select **Debug and Launch Settings**. This will open an existing **launch.vs.json** file, or if none exists, it will create a new file prepopulated with the information about the program you have selected.
164
+
To customize your program’s command line arguments, right-click on the executable in **Solution Explorer** and select **Debug and Launch Settings**. This will open an existing **launch.vs.json** file, or if none exists, it will create a new file that is pre-populated with the information about the program you have selected. First you are given a choice of what kind of debug session you want to configure. For debugging a MinGw-w64 project, we choose **C/C++ Launch for MinGGW/Cygwin (gdb)**. This creates a launch configuration for using *gdb.exe* with some educated guesses about default values. Since we did not define a variable called `MINGW_PREFIX` we can just substitute the literal path:
To start debugging, choose the executable in the debug dropdown, then click the green arrow:
187
+
188
+

189
+
190
+
You should see the **Initializing Debugger** dialog and then an external console window that is running your program.
191
+
85
192
86
-
To specify additional arguments, just add them in the `args` JSON array as shown in the following example:
193
+
You can define launch settings for any executable on your computer. The following example launches *7za* and specifies additional arguments, by adding them to the `args` JSON array:
0 commit comments