In the previous articles, we have mentioned Visual Studio shortcuts and Visual Studio useful Extensions now in this article, I have explained the difference between Build, Re-Build and Clean solution options available in Visual Studio Solutions.

Visual Studio is an Integrated Development Environment developed by Microsoft, using which you can create various types of applications like web-application, mobile applications, or Desktop applications. You can code in C#, C++, Python, etc programming languages using Visual Studio IDE. It provides us a feature to build or re-build solutions, let's understand what do these terms mean.

Build: When a programmer writes a code in Visual Studio and then try to compile the code, then the programmer and choose to "build" the solution, so VS can check any compilation errors and if there isn't one, generate the .dll/exe files.

Rebuild: When the programmer updates the code, then he/she can simply re-build the entire solution or project whcih deletes all compiled files and compiles them again, check compilation error, and generate .dll/exe files again.

Clean: Clean will simply remove all compiled files (.dll and .exe files).

Build vs Rebuild in Visual Studio

visual-studio-build-rebuild-min.png

Build solution will perform an incremental build, if the assembly has no change then it will not re-build. It may also use partially-built bits of the project if they haven't changed.

Programmers can use build to compile the entire solution.

This is the faster option to compile and run your solution in Visual Studio.

Rebuild solution will clean and then build the solution from scratch, ignoring anything it's done before. So rebuild will clean-then-build each project, one at a time, rather than cleaning all and then building all.

It rebuilds all assemblies regardless of changes but leaves intermediate files.

Programmers can use rebuild to remove created compiled files and to compile the entire solution again.

Example:

Let’s say your solution has two projects, "projectName1" and "projectName2". If you do a rebuild it will take "projectName1", clean (delete) the compiled files for "projectName1" and build it.

After that, it will take the second project "projectName2", clean compiled files for "projectName2" and compile "projectName2".

But if you do a "clean" and "build", it will first delete all compiled files for "projectName1" and "projectName2" and then it will build "projectName1" first followed by "projectName2".

How to build, rebuild or clean the entire solution

You can follow these steps in your Visual Studio

  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 Solution to compile only those project files and components that have changed since the most recent build.
    • 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.

How to build or rebuild a single project

Follow these steps to build or rebuild any single project when you have multiple projects in Visual Studio solution

  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 YourProjectName to build only those project components that have changed since the most recent build.
    • Choose Rebuild YourProjectName to "clean" the project and then build the project files and all project components.

You may also like to read:

Hello World C# program with explanation of code

Best IDE for Web Development (C#, ASP.NET, Java , PHP, HTML, Javascript)

How to debug in visual studio? ( Tutorial to debug C# code )