Back to Basics – Building Solutions in Visual Studio – Build Vs. Rebuild

Back to Basics – Building Solutions in Visual Studio – Build Vs. Rebuild

Build Solution” and “Rebuild Solution” are the most commonly used features in Visual Studio.  As a developer you writes code, build the solution and run the application in Visual Studio.  Very often you also used “rebuild solution” , or “clean and then build solution”.  Have you ever wonder why there are different options ? When to use them?  Though many of you are familiar with the details of  these but when asked, I have seen many beginners having confusion around it.

So let’s try to simply it by asking below questions

  • What is the difference between Build and Rebuild ?
  • When to use which option ?
  • How does clean relates , when to use it ?

image

 One-liner Understanding…

  • Build Solution – Incremental build and compiles only the files that are changed.
  • Clean Solution – Deletes all compiled, intermediate files.
  • Rebuild Solution – Deletes all compiled files and compiles all irrespective of changes.

 

image

Now take a deeper look ….

Build Solution

This is the faster option to compile and run your solution in Visual Studio. When you opt for the Build, Visual Studio will perform an incremental build.  What does it mean ?

  • Builds any assemblies which have changed files from the last build. If there an assembly which has no changes, it won’t be re-built.
  • During the Build option, Visual Studio won’t  delete any intermediate files.

image

So, for a single solution, if you build it for first time, and verify the detailed log at output window, you should be able to see information as similar to shown in below..

image

If here is no changes, and try to build it again, it will display message like below – which says .. all the code base are up-to-date

image

Incase there are multiple projects, all up-to-date projects will be skipped and only the changed files will be built.

image

Clean Solution

This will remove all intermediary, complied files and clean up the output directories (bin / obj folders) from any previous builds.

Detailed wiew of Output Windows will display very similar information like shown in below screenshot…

image

When execute, Clean Solutions, Cleans the project one by one.

image

image

Now if you execute build after the clean, you will have following steps of execution ( Post Clean Solution)

image

Rebuild Solution

As mentioned earlier, rebuild a solution is nothing but clean and build each project in the solution.

image

Rebuilding a solution first does the “Clean Solution” then execute the “Build Solution” for each project.

image

 

Note: This sequence of project execution from the list of project will depends on the project dependency.  For an instance, project build sequence for below two different dependency diagram would be different.

imageimage

 

 

 

 

 

 

 

Well, just to summarize let me write done the same one-liners once again

Build Solution – Incremental Build and Compiles only the files that are changed.

Clean Solution – Deletes all compiled, intermediate files

Rebuild Solution – Deletes all compiled files and Compiles them all irrespective of changes

 

Hope it was helpful …

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

3 Comments to “Back to Basics – Building Solutions in Visual Studio – Build Vs. Rebuild”

Comments are closed.