For some, as yet to be understood, reason after a few debug sessions some of the dependant DLLs become locked by Visual Studio and the build stage cannot overwrite the DLLs. Today I finally decided to see if anyone else was have the same problem and found this in Gary Farr’s blog (copied in case the blog becomes unavailable);
VS basically locks the file and you cannot use third party resources to unlock it. Therefore, just use VS! In the Properties of a project in your IDE you have Buld Events. Basically, you can write scripts during pre and post builds of a project. I added these two lines in the pre-build event command line, which basically unlocks the dll within Visual Studio.
IF EXIST $(TargetPath).LOCKED (del $(TargetPath).LOCKED) ELSE (IF EXIST $(TargetPath) (move $(TargetPath) $(TargetPath).LOCKED))