For one of my ASP.NET 3.5 applications, every single time I try to build the web app, it throws the following build errors in Visual Studio 2008:
Error 16
you can also delete bin and obj folders in all projects in solution then rebuild solution.
File locks are just part of working with Visual Studio. There aren't any great ways to get around this problem.
I was using Visual Studio 2012 when this started happening on a 7 year old solution (for the second or third time: I've been to this question before).
I tried the various voodoo. I cleaned the solution. Didn't work. I restarted Visual Studio. Didn't work. I was confident that last one would work, because that is the voodoo that worked last time.
Ultimately, I remembered a security update had installed last night and was configured when I started my machine this morning - (Connected or not? No Idea) - So, I restarted Windows, and voila, it all worked like magic again.
Thanks MS for more mind mincing.
Similar to Benoit's answer but doesn't require any tool installation, you can use tasklist (task manager) command at the command line with the '/m' switch to get a list of processes using the dll:
tasklist /m mylocked.dll
I saw some posts indicating you have to do it from the directory of the offending dll, but I haven't found that to be the case.
This happens to me sometimes when using Visual Nunit for unit tests.
It seems the process 'VisualNunitRunner.exe' locks the .dll files in the destination directory.
I used Unlocker to find the process, kill it or unlock the files.
If you have Visual Nunit, it must be locking dll file.