What is the difference between just a Rebuild and doing a Clean + Build in Visual Studio 2008? Is Clean + Build different then doing Clean + Rebuild?
6 Answers
Rebuild = Clean + Build (usually)
Notable details:
For a multi-project solution, "rebuild solution" does a "clean" followed by a "build" for each project (possibly in parallel). Whereas a "clean solution" followed by a "build solution" first cleans all projects (possibly in parallel) and then builds all projects (possibly in parallel). This difference in sequencing of events can become significant when inter-project dependencies come into play.
All three actions correspond to MSBuild targets. So a project can override the Rebuild action to do something completely different.
Earl is correct that 99% of the time Rebuild = Clean + Build.
But they are not guaranteed to be the same. The 3 actions (rebuild, build, clean) represent different MSBuild targets. Each of which can be overriden by any project file to do custom actions. So it is entirely possible for someone to override rebuild to do several actions before initiating a clean + build (or to remove them entirely).
Very much a corner case but pointing it out due to comment discussions.
Let's define default Rebuild implementation in terms of default Clean and Build implementations:
Per project: Rebuild project = Clean project + Build project.
Per solution: Rebuild sln = foreach project in sln (Clean project + Build project).
Note that due to differences in the order of execution, Rebuild sln is not the same as (Clean sln + Build sln) = (foreach project in sln Clean project) + (foreach project in sln Build project). Also, this "foreach" may execute concurrently, so different tasks are allowed to run concurrently in the two scenarios.
Say you have a sln that contains proj1, proj2, and proj3.
Rebuild sln = (Clean proj1 + Build proj1) & (Clean proj2 + Build proj2) & (Clean proj3 + Build proj3)
Clean Sln + Build Sln = (Clean proj1 & Clean proj2 & Clean proj3) + (Build proj1 & Build proj2 & Build proj3)
+ means serial, & means concurrent.
So if project dependencies are not configured correctly, there is a chance that when you execute Rebuild sln, some of your projects link to a stale lib. That's because all cleans are not guaranteed to be finished before the first build starts. If you execute Clean sln + Build sln, they will give a link error and let you know that immediately, instead of giving you an app with odd behavior.
From http://www.cs.tufts.edu/r/graphics/resources/vs_getting_started/vs_getting_started.htm, (just googled it):
Build means compile and link only the source files that have changed since the last build, while Rebuild means compile and link all source files regardless of whether they changed or not. Build is the normal thing to do and is faster. Sometimes the versions of project target components can get out of sync and rebuild is necessary to make the build successful. In practice, you never need to Clean.
Build or Rebuild Solution builds or rebuilds all projects in the your solution, while Build or Rebuild builds or rebuilds the StartUp project, "hello" in the screen shot above. To set the StartUp project, right click on the desired project name in the Solution Explorer tab and select Set as StartUp project. The project name now appears in bold. Since the homework solutions typically have only one project, Build or Rebuild Solution is effectively the same as Build or Rebuild .
Compile just compiles the source file currently being edited. Useful to quickly check for errors when the rest of your source files are in an incomplete state that would prevent a successful build of the entire project. Ctrl-F7 is the shortcut key for Compile.
From this blog post which the author linked as a comment on this question:
Actually No!!! they are not equal.
The difference is in the sequence projects get clean and build. Let say we have two projects in a solution. Clean and then build will perform clean to both projects and then build will occur individually while on rebuild project A will get and clean and then build after that project B will be clean and then build and so on.