Wednesday, February 27, 2013

Visual studio locking files on build

More and more I got a problem with visual studio blocking files on build, (Could not copy dll from debug to bin) mostly in web projects (MVC).
A solution was to clean the solution (getting the same error),
waiting a few seconds, cleaning again,
and then building.
Now I found a solution that seems to work,
right click the project,
properties,
Build steps,
and add to the pre build command line :
if exist "$(TargetPath).locked" del "$(TargetPath).locked" if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

(You need to copy the double quotes too).
It might be needed to add this to more than one project in your solution, just look at the error you get when building.

No comments: