What is the difference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio?
When is the appropriate time to use each one of these?
What is the difference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio?
When is the appropriate time to use each one of these?
(The links are to the devenv.exe command line switches, but they do the same as the menu items.)
The one major thing I think people are leaving out is that Build and Clean are both tasks that are performed based on Visual Studio's knowledge of your Project/Solution. I see a lot of complaining that Clean doesn't work or leaves leftover files or is not trustworthy, when in fact, the reasons you say it isn't trustworthy actually makes it more trustworthy.
Clean will only remove (clean) files and/or directories that Visual Studio or the compiler themselves have in fact created. If you copy your own files or files/folder structures get created from an outside tool or source, then Visual Studio doesn't "know they exist" and therefore, should not touch them.
Can you imagine if the Clean operation basically performed a "del *.*" ? This could be catastrophic.
Build performs a compile on changed or necessary projects.
Rebuild performs a compile regardless of change or what's necessary.
Clean removes files/folders it has created in the past, but leaves anything that it didn't have anything to do with, initially.
I hope this elaborates a bit and helps.
All I know is a Clean does not do what "make clean" used to do - if I Clean a solution I would expect it delete obj and bin files/folders such that it builds like is was a fresh checkout of the source. In my experience though I often find times where a Clean and Build or Rebuild still produces strange errors on source that is known to compile and what is required is a manual deletion of the bin/obj folders, then it will build.
Build solution: Compiles code files (DLL and EXE) which are changed.
Rebuild: Deletes all compiled files and compiles them again irrespective if the code has changed or not.
Clean solution: Deletes all compiled files (DLL and EXE file).
You can see this YouTube video (Visual Studio Build vs. Rebuild vs. Clean (C# interview questions with answers)) where I have demonstrated the differences and below are visual representations which will help you to analyze the same in more detail.
The difference between Rebuild vs. (Clean + Build), because there seems to be some confusion around this as well:
The difference is the way the build and clean sequence happens for every project. Let’s say your solution has two projects, “proj1” and “proj2”. If you do a rebuild it will take “proj1”, clean (delete) the compiled files for “proj1” and build it. After that it will take the second project “proj2”, clean compiled files for “proj2” and compile “proj2”.
But if you do a “clean” and build”, it will first delete all compiled files for “proj1” and “proj2” and then it will build “proj1” first followed by “proj2”.
Taken from this link:
Build Solution – Builds any assemblies which have changed files. If an assembly has no changes, it won’t be re-built. Also will not delete any intermediate files.
Rebuild solution will clean and then build the solution from scratch, ignoring anything it’s done before
Clean Solution will delete all compiled files (i.e., EXE’s and DLL’s) from the bin/obj directory.