Build and clean projects and solutions in Visual Studio

By using the procedures in this topic, you can build, rebuild, or clean all or some of the projects or project items in a solution. For a step-by-step tutorial, see Walkthrough: Building an application.

Note

This topic applies to Visual Studio on Windows. For Visual Studio for Mac, see Build and clean projects and solutions in Visual Studio for Mac.

Note

The UI in your edition of Visual Studio might differ from what this topic describes, depending on your active settings. To change your settings, for example to General or Visual C++ settings, choose Tools > Import and Export Settings, and then choose Reset all settings.

To build, rebuild, or clean an entire solution

  1. In Solution Explorer, choose or open the solution.

  2. On the menu bar, choose Build, and then choose one of the following commands:

    • Choose Build or Build Solution, or press Ctrl+Shift+B, to compile only those project files and components that have changed since the most recent build.

      Note

      The Build command becomes Build Solution when a solution includes more than one project.

    • Choose Rebuild Solution to "clean" the solution and then build all project files and components.

    • Choose Clean Solution to delete any intermediate and output files. With only the project and component files left, new instances of the intermediate and output files can then be built.

To build or rebuild a single project

  1. In Solution Explorer, choose or open the project.

  2. On the menu bar, choose Build, and then choose either Build ProjectName or Rebuild ProjectName.

    • Choose Build ProjectName to build only those project components that have changed since the most recent build.

    • Choose Rebuild ProjectName to "clean" the project and then build the project files and all project components.

To build only the startup project and its dependencies

  1. On the menu bar, choose Tools > Options.

  2. In the Options dialog box, expand the Projects and Solutions node, and then choose the Build and Run page.

    The Build and Run > Projects and Solutions > Options dialog box opens.

  3. Select the Only build startup projects and dependencies on Run check box.

    When this check box is selected, only the current startup project and its dependencies are built when you choose Debug > Start (F5) or Debug > Start Without Debugging (Ctrl+F5).

    When you choose Build > Build Solution (Ctrl+Shift+B), the entire solution is built.

    When this check box is cleared, all projects, their dependencies, and the solution files are built when you run any of the preceding commands.

To build only the selected Visual C++ project

Choose a C++ project, and then, on the menu bar, choose Build > Project Only, and one of the following commands:

  • Build Only ProjectName

  • Rebuild Only ProjectName

  • Clean Only ProjectName

  • Link Only ProjectName

These commands apply only to the C++ project that you chose, without building, rebuilding, cleaning, or linking any project dependencies or solution files. Depending on your version of Visual Studio, the Project Only submenu might contain more commands.

To compile multiple C++ project items

In Solution Explorer, choose multiple files that can be compiled, open the shortcut menu for one of those files, and then choose Compile, or press Ctrl+F7.

If the files have dependencies, the files will be compiled in dependency order. The compile operation will fail if the files require a precompiled header that isn't available when you compile. The compile operation uses the current active solution configuration.

To stop a build

Perform either of the following steps:

  • On the menu bar, select Build > Cancel.

  • Press Ctrl+Break.