Sunday, July 21, 2013

.NET interview questions with answers: - Build solution VS Rebuild solution VS Clean solution

I am not aware of a single day in my life when I have not clicked on “Build”, “Rebuild” or “Clean” menu of visual studio. Even though I use it on a daily basis  or sometimes even minute to minute basis when my keyboard was high on coding, I was still not clear what exactly each one of these menus do.  I had very vague idea, but I wanted to be sure about the exact differences between them.

When I hunted the differences what came out was surprising, below goes a detailed explanation of the same.


Build solution menu: - This will perform an incremental build. In other words it will only build code files which have changed. If they have not changed those files will not touched.

Rebuild solution menu: - This will delete all current compiled files (i.e. exe and dll’s) and will build everything from scratch, irrespective if there is code change in the file or not.


Clean solution menu: - This menu will delete all compiled files (i.e. EXE’s and DLL’s) from “bin” / “obj” directory.

Now if you read the above 3 points I have discussed you can conclude that:-

Rebuild = Clean + Build

So the next question would be If you do a “Rebuild” and if you do “Clean” + “Build” , what is the difference ?.

The difference is the way the build and clean sequence happens for every project. Let’s say if 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”.

Below image explains the same in a more visual format.


















Below is a simple youtube video which demonstrates difference between these entities.



Big thanks to questpond.com to provide these c# and .NET interview questions with answers videos.






2 comments:

Unknown said...

Thank you very much for this post.
Finally which one is the best. Rebuild or Clean+Rebuild

Unknown said...

Thank you very much for this post.
Finally which one is the best. Rebuild or Clean+Rebuild ?