If you are building inside Visual Studio, dependencies for the solution (which can be explicit or based on project references) are used to determine which projects need to be built, and a separate assembly is opened for each of them. This is necessary because solutions may also contain projects that are not built using MSBuild, while other projects have explicit dependencies set in the solution for them. A side effect is that each project is considered as a standalone assembly, which ensures the correct BeforeBuild order for you.
If you are building from the command line using MSBuild, dependency projects are resolved (and if necessary created) during the ResolveReferences target. The BeforeBuild target and PreBuild (executed from the PreBuildEvent target) are executed before the ResolveReferences target. Thus, the BeforeBuild target project ends with execution before the build for the dependency project is started.
Please note that from the point of view of one project, the BeforeBuild target makes sense before resolving the dependencies, since resolving the dependencies may depend on the BeforeBuild target output. For example, BeforeBuild can execute a custom script to get the latest copy of any dependency projects from SCM .
Franci penov
source share