What is the difference between Build and Rebuild in Visual Studio?
If you are a developer that uses Visual Studio as your IDE, you will be familiar with the Build and Rebuild tasks. I regularly write code in Visual Studio and am used to hitting the Build command when I am developing, but have often wondered what is actually happening under the hood. It seems like a simple question, but what really is the difference between Build and Rebuild in Visual Studio? And how does Clean fit in?
Build Solution
This is actually Visual Studio's lazier and possibly faster option when it comes to compiling a solution. When you Build a solution, Visual Studio will perform an incremental build under the hood. This means that if it doesn't think it's necessary to rebuild a certain project within the solution it won't. This can be quite useful if you are only working in one project in a solution and can be noticeably faster.
Rebuild Solution
When you Rebuild a solution, this command actually cleans and then builds each project in the solution from scratch. It is quite clever in that it will ignore a project that it has already cleaned and built.
Clean Solution
I have found myself in many a sticky situation and the Clean Solution command has helped me out. Under the hood, this command will remove all intermediary files and output directories (your bin and obj folders) from the previous build. After performing a Clean and navigating to your output directories, you may notice that not all of the files are actually removed. This might happen because Clean only removes files that are associated with a build and not everything else. If you are looking for a way to remove all files when you run the Clean command, there is a great post on Stack Overflow worth checking out.
If you'd like to find out more about the different build and rebuild commands in Visual Studio, I recommend taking a look at the MSDN docs.