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))
 
Advertisements
This entry was posted in Visual Studio. Bookmark the permalink.

2 Responses to Problems with locked DLLs when compiling in Visual Studio

  1. Patrick Kursawe says:

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

  2. John oliver says:

    I found a Visual Studio 2015 Extension for this. UnBlockDllExtension
    https://marketplace.visualstudio.com/items?itemName=NithinVR.UnBlockDllExtension

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s