Problems with locked DLLs when compiling in Visual Studio

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);
 
Final solution:
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))
 

2 thoughts on “Problems with locked DLLs when compiling in Visual Studio

  1. Patrick Kursawe January 31, 2013 / 8:27 am

    Looked nice, but didn’t help in my case. When this madness starts, I have to restart VS for each debugger run.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s