I had a client recently that was having a big problem with builds on dev machines failing due to files being locked and unable to be deleted. The problem irregular and it was causing the developers to get frustrated and waste a lot of time in stopping and restarting Visual Studio to try and release the locks.

The errors the team were seeing were all similar to this:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning MSB3061: Unable to delete file "C:\WebApplication\bin\Web.dll". Access to the path 'C:\WebApplication\bin\Web.dll' is denied.


The application itself was a web application, build on XP machines running VS2005 SP1 and set to use IIS as the default web server (i.e. the application virtual directory was pointed at the source code folder).


The team had already checked that the indexing service was off and that antivirus wasn't locking files.  When using the sysinternals utilities to see what other processes were locking those files nothing appeared apart from devenv.exe itself (i.e. visual studio).


The problem as it turned out was in the settings of the virtual directory in IIS6.  The virtual directory still had the "index this location" flag turned on.  It turned out that IIS was placing a temporary lock on these files, even though the web application wasn't being started (ie it was just a compile, not a debug run).  Why this didn't appear in the sysinternals utilities I'm not sure.


Anyway, after turning the "index this location" setting off the file locking problem disappeared and the devs started smiling again.  Happy days :-)