Dela via


Building and Cleaning 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

The UI in your edition of Visual Studio might differ from what this topic describes, depending on your active settings. To change your settings, open the Tools menu, and then choose Import and Export Settings. For more information, see Customizing Development Settings in Visual Studio.

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 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 BuildProjectName or RebuildProjectName.

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

    • Choose RebuildProjectName 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 perform either of the following steps:

    • On the menu bar, choose Debug, Start (F5).

    • On the menu bar, choose Build, Build Solution (CTRL+SHIFT+B).

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

To build only the selected Visual C++ project

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

    • Build OnlyProjectName

    • Rebuild OnlyProjectName

    • Clean OnlyProjectName

    • Link OnlyProjectName

    These commands apply only to the Visual 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 have can be compiled actions, open the shortcut menu for one of those files, and then choose Compile.

    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, choose Build, Cancel.

    • Choose the Ctrl + Break keys.

See Also

Tasks

How to: View, Save, and Configure Build Log Files

Reference

Debug and Release Project Configurations

Devenv Command Line Switches

Concepts

Obtaining Build Logs with MSBuild

Understanding Build Configurations

Solutions and Projects

Other Resources

Building Applications in Visual Studio

C/C++ Building Reference