45

I do not know if i understood right , the difference between a "build" and "rebuild" command of a project in Visual Studio is the fact that a build only compiles the code which was changed , since a "rebuild" command compiles all the code from project regardless is it was changed or not.

Also a rebuild command includes a clean of the project, since build command does not ?

Please advice me to understand better these differences.

Thanks !

Mircea
  • 3,369
  • 6
  • 27
  • 26
  • 3
    __Related #1__: [Difference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio](https://stackoverflow.com/q/3095901/3367974), __Related #2__: [Difference between Rebuild and Clean + Build in Visual Studio](https://stackoverflow.com/q/1247457/3367974) – Mehdi Dehghani Jun 29 '17 at 10:42

3 Answers3

37

Also a rebuild command includes a clean of the project, since build command does not ?

You have identified the fundamental difference.

Build will look at the files that have been modified since the last successful compile and link and just compile those and then link the result.

Rebuild will recompile everything.

Strictly speaking it might be different to a clean (which removes the intermediate and output files) and build and just recompile everything, but the result should be the same. However, there may be cases that fail (see Femaref's comment).

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • 2
    To your last point: It depends. In some cases, remaining temporary files or changed references might disrupt your build, especially with the later case, as no code changed, but the old references are still used. A clean is needed to replace those. – Femaref Dec 11 '10 at 13:22
  • 2
    Not sure why, but sometimes clean does not seem to get rid of all the old references. When this happens, I will delete the obj directory. – Trevor Tubbs Dec 11 '10 at 13:33
30

Build means to compile all the code that was altered or written after the last compilation.

Rebuild means to compile the whole project regardless of whether or not the code was changed.

So, after making you read my answer, yes you would be correct.

Nateeo
  • 495
  • 3
  • 5
1

As far as I experience, if your dlls/exes are needed to be copied via post build and the location to where the files are copied is locked or otherwise due to another problem, somehow the files are not able to be copied but the compilation is done without any issue, you need to rebuild in this case.