When should you prefer ReBuild instead of Build?
Asked Answered
D

2

10

Just to make it more clear for me, I would like to ask you guys the correct condition(s) to have your

project or solution Rebuild instead of build in Visual Studio?

If I rephrase it: Why the MS needed to create "Re-build ALL" option in Visual Studio? What was their main motive to do that?

Thanks!

Declinometer answered 15/11, 2010 at 8:22 Comment(0)
O
7

DRY : Rebuild = Clean + Build for each project in turn.

Build does not delete the previous builds outputs. Rebuild does delete them and build again (one project at a time if you are in a solution : delete proj1\bin\Debug, build proj1, delete proj2\bin\Debug ...).

The main case when I do a rebuild (or a clean build) is when I need to update my solution third dependencies. Let's see the following folder tree :

    SOLUTION
      |__Dependencies
      |__PROJ_1
         |__bin
         |__obj
         |__(code)
      |__PROJ_2
         |__bin
         |__obj
         |__(code)

If I change my dlls in Dependencies and don't do a rebuild, VS (and MsBuild) would still use the previous dll version that is in PROJ_N\bin\Debug (or in bin\Release), because of the Dependency lookup order (see http://www.beefycode.com/post/Resolving-Binary-References-in-MSBuild.aspx) :

  1. Files from current project - indicated by {CandidateAssemblyFiles}
  2. $(ReferencePath) - the reference path property, which comes from the .USER file.
  3. The hintpath from the referenced item itself, indicated by {HintPathFromItem}.
    ...

The dll in bin folder goes in the the first lookup case, the dll in Dependencies folder comes in the second case...

In such a case I would do a clean (Debug), clean (Release) and then a build to eradicate all previous version in the bin folder. I'm maybe a bit overkill and a rebuild may be enough but I'm not sure because the dlls are in the Debug and in the Release folders...

Opaque answered 15/11, 2010 at 9:24 Comment(4)
In another words, Rebuild = Clean + BuildHammerlock
Most of the time, and for a single project, yes. See #1247957 .Opaque
In your Microsoft.Common.Targets, you can see that for a project Rebuild = BeforeRebuild; Clean; $(_ProjectDefaultTargets);AfterRebuild;Opaque
@ abatishchev : And "Clean" is required when something is changed out of your source code which is consumed by your "source code." An example with MILITARY terms: If you are a soldier guarding the base's gate and if the "password" is changed to authorize the guests through the gate, you have to delete your "old password" and obtain the "new password" so that you operate correctly!Declinometer
N
1

Sometimes things go wrong and the build just doesn't work.

This happens e.g. when I do not correctly update dependent libraries which then aren't correctly copied to the bin paths of the build. There are other examples, non spring to mind.

That's when I use rebuild.

Neology answered 15/11, 2010 at 8:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.