MSBuild is the native build system for Visual Studio and is the best choice for Windows-specific C++ applications. A Visual Studio C++ project is represented by aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/MicrosoftDocs/cpp-docs/llms.txt
Use this file to discover all available pages before exploring further.
.vcxproj XML file that describes source files, compiler options, linker options, and custom build steps. MSBuild is tightly integrated with the Visual Studio IDE — property pages expose every build setting with documentation, and the build engine supports incremental compilation, parallel builds, and multi-project solutions. You can also invoke MSBuild directly from the command line, making it suitable for CI pipelines that do not need the full IDE.
Creating a Visual Studio C++ Project
New Project Dialog
Select File → New → Project. In the Create a new project dialog, set the Language filter to C++. Choose a project template such as Console App, Windows Desktop Application, Dynamic-Link Library (DLL), or Static Library, then click Next.
Configure Project
Enter the project name, location, and solution name on the Configure your new project page. Click Create. Visual Studio creates a
.vcxproj file, a .sln solution file, and default source files.Add Source Files
Right-click the project in Solution Explorer and choose Add → New Item or Add → Existing Item to add
.cpp and .h files to the project.Understanding the .vcxproj File
A.vcxproj file is an MSBuild XML project file. You rarely edit it by hand, but understanding its structure helps when troubleshooting or applying bulk changes.
Project Properties
Open the Property Pages dialog (Project → Properties or right-click the project in Solution Explorer). All settings are scoped to a Configuration (Debug, Release, or custom) and Platform (Win32, x64, ARM, ARM64).Key Property Categories
General
General
| Property | Description |
|---|---|
| Output Directory | Directory for the final .exe, .dll, or .lib. Default: $(SolutionDir)$(Platform)\$(Configuration)\ |
| Intermediate Directory | Directory for .obj and .pch files. Default: $(Platform)\$(Configuration)\ |
| Configuration Type | Application (.exe), Dynamic Library (.dll), Static library (.lib) |
| Platform Toolset | MSVC toolset version (v143 = VS 2022, v142 = VS 2019) |
| C++ Language Standard | Maps to /std:c++14, /std:c++17, /std:c++20, /std:c++latest |
C/C++ → General
C/C++ → General
| Property | Compiler Flag | Description |
|---|---|---|
| Additional Include Directories | /I | Semicolon-separated list of paths to search for #include files |
| Debug Information Format | /Z7, /Zi, /ZI | Where debug symbols are stored |
| Warning Level | /W0–/W4, /Wall | Compiler warning verbosity |
| Treat Warnings As Errors | /WX | Fail the build on any warning |
| SDL Checks | /sdl | Enable additional Security Development Lifecycle checks |
C/C++ → Preprocessor
C/C++ → Preprocessor
| Property | Compiler Flag | Description |
|---|---|---|
| Preprocessor Definitions | /D | Semicolon-separated list, e.g. WIN32;NDEBUG;_CONSOLE |
| Undefine Preprocessor Definitions | /U | Remove a previously-defined macro |
%(PreprocessorDefinitions) to inherit the parent scope’s definitions:C/C++ → Optimization
C/C++ → Optimization
| Property | Compiler Flag | Description |
|---|---|---|
| Optimization | /Od, /O1, /O2, /Ox | Disabled, minimize size, maximize speed, or full |
| Inline Function Expansion | /Ob0, /Ob1, /Ob2 | Controls inlining aggressiveness |
| Intrinsic Functions | /Oi | Replace function calls with compiler intrinsics |
| Favor Size or Speed | /Os, /Ot | Trade size for speed or vice-versa |
| Whole Program Optimization | /GL | Enable cross-module optimization (use with /LTCG) |
C/C++ → Code Generation
C/C++ → Code Generation
| Property | Compiler Flag | Description |
|---|---|---|
| Runtime Library | /MD, /MT, /MDd, /MTd | Link to DLL or static CRT |
| Enable C++ Exceptions | /EHsc | Enable standard C++ exception handling |
| Enable Run-Time Type Information | /GR | Enable dynamic_cast and typeid |
| Security Check | /GS | Buffer overrun detection |
| Struct Member Alignment | /Zp | Override default struct packing |
Linker → General
Linker → General
| Property | Linker Flag | Description |
|---|---|---|
| Output File | /OUT | Name of the output file |
| Additional Library Directories | /LIBPATH | Extra paths to search for .lib files |
| Enable Incremental Linking | /INCREMENTAL | Speed up repeated links at the cost of some size |
Linker → Input
Linker → Input
| Property | Linker Flag | Description |
|---|---|---|
| Additional Dependencies | (listed libs) | Explicit .lib files to link against, e.g. kernel32.lib;user32.lib |
| Ignore All Default Libraries | /NODEFAULTLIB | Do not link CRT or Windows SDK default libs |
| Ignore Specific Default Libraries | /NODEFAULTLIB:name | Exclude a named library |
Using Property Sheets (.props)
Property sheets allow you to define shared settings once and apply them across multiple projects. This is the recommended way to share include paths, preprocessor definitions, and library paths across a solution. Creating a property sheet:- Open View → Property Manager.
- Right-click a project and choose Add New Project Property Sheet.
- Name the file (e.g.,
SharedSettings.props) and save it at the solution root. - Edit the sheet to add common settings.
.vcxproj that needs it:
Multi-Project Solutions
A Visual Studio solution (.sln) coordinates multiple projects. The solution file tracks project dependencies and the build order.
Adding a project to an existing solution:
Right-click the solution node in Solution Explorer → Add → New Project or Add → Existing Project.
Setting project dependencies:
Right-click the solution in Solution Explorer → Project Dependencies. Check which projects must build before others.
Referencing another project:
Right-click the consuming project in Solution Explorer → Add → Reference, and select the project to reference. This automatically adds the correct .lib output to the linker’s input list and establishes a build dependency.
Example: a solution with a library and an application:
Building with MSBuild from the Command Line
After setting up the MSVC environment (see Command-Line Builds), you can invoke MSBuild directly:Starting in Visual Studio 2019 version 16.5, MSBuild does not use the command-line environment to determine the toolset. Always set the platform using
/p:Platform= rather than relying on environment variables.Target Platforms
Visual Studio C++ projects support multiple target architectures via the Platform configuration:| Platform Name | Target Architecture |
|---|---|
Win32 | 32-bit x86 Windows |
x64 | 64-bit x64 Windows |
ARM | 32-bit ARM Windows |
ARM64 | 64-bit ARM64 Windows |