Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent Visual Studio from locking the xml documentation files in the bin directory?

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?

like image 364
SteveBering Avatar asked Jul 22 '09 19:07

SteveBering


2 Answers

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

like image 50
knst Avatar answered Nov 18 '22 08:11

knst


If you're fine with omitting the xml & pdb files altogether from the output, you can pass /p:AllowedReferenceRelatedFileExtensions=none to msbuild on the command line.

(Thanks to related answer https://stackoverflow.com/a/8757941/251011 )

EDIT: If you also have problems with dll files having this error, I recently discovered an environment variable solution: https://stackoverflow.com/a/23069603/251011

like image 2
Mike Asdf Avatar answered Nov 18 '22 08:11

Mike Asdf