How to prevent Visual Studio from locking the xml documentation files in the bin directory

lockingmsbuildxml-documentation

My visual studio solution includes a web application and a unit test application. My web application uses log4net. I want to be able to use msbuild from the command-line to build my solution. However, whenever I build the solution from the command-line, I get build errors because it can't copy log4net.xml to the test project's bin directory.

The error message is:

"Unable to copy file '\bin\log4net.xml' to 'bin\Debug\log4net.xml'. Access to the path '\bin\log4net.xml' is denied."

It looks like Visual Studio is locking this file, but I can't figure out why it would need to. Is there a way to prevent VS from locking the XML documentation files in a project that it has loaded?

Best Answer

I've found the following solution: In VS postbuild event or in NAnt/MSbuild script execute the cmd script

handle.exe -p devenv [Path to the folder with locked files] > handles.txt

FOR /F "skip=5 tokens=3,4 delims=: " %%i IN (handles.txt) DO handle -p %%i -c %%j -y

handle.exe is available here http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx

first line of the script dumps to handles.txt all handles for files locked by VS second line reads handle ids from the file and kills the handles

After the script is executed files may be removed/replaced/moved etc