views:

115

answers:

5

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?

+7  A: 

Taken from this link:

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.

Matthew Jones
+1 because you were first.
ChrisF
A: 

Build solution will build any projects in the solution that have changed. Rebuild builds all projects no matter what, clean solution removes all temporary files ensuring that the next build is complete.

SnOrfus
+1  A: 

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.

Used most commonly.

Rebuild Solution - Rebuilds all assemblies regardless of changes but leaves intermediate files.

Used when you notice that Visual Studio didn't incorporate your changes in the latest assembly. Sometimes Visual Studio does make mistakes.

Clean Solution - Delete all intermediate files and rebuild all assemblies regardless of changes

Used when all else fails and you need to clean everything up and start fresh.

Justin Niessner
Clean doesn't do a build.
Jon Skeet
@Jon Skeet - Learn something new every day. I would've sworn it did a rebuild. I guess my memory isn't always as reliable as I'd like.
Justin Niessner
+8  A: 
  • Build solution will perform an incremental build: if it doesn't think it needs to rebuild a project, it won't. It may also use partially-built bits of the project if they haven't changed (I don't know how far it takes this)
  • Rebuild solution will build the solution from scratch, ignoring anything it's done before
  • Clean solution will remove the build artefacts from the previous build. If there are any other files in the build target directories (bin and obj) they may not be removed, but actual build artefacts are. I've seen behaviour for this vary - sometimes deleting fairly thoroughly and sometimes not - but I'll give VS the benefit of the doubt for the moment :)

(The links are to the devenv.exe command line switches, but they do the same as the menu items.)

Jon Skeet
Ah. I'm about to get outvoted, I see. :)
Matthew Jones
@Jon - a Clean does wipe the bin and obj folders in my experience?
womp
@womp: Not in the project I've just been looking at. It's still got all the assemblies there...
Jon Skeet
Ah, hang on... editing.
Jon Skeet
@Jon - weird. I don't recall a clean ever not cleaning up those directories. I'm doing it right now and it's wiping all .dll and .pdb files. Definitely leaves my ReSharper junk alone though.
womp
A: 

I just think of Rebuild as performing the Clean first followed by the Build. Perhaps I am wrong ... comments?

orvado