TFS 2010 The directory is not empty issue RRS feed

  • Question


    I did some many researches over the internet trying to find out the way to resolve this "Directory is not empty" issue in past a few weeks.

    Even after running ProMon.exe but it was nothing but frustration that I want to share how I get away with it and hope that someone can provide me the answer.

    So, the problem is that, even when I'm using default template.xaml to run a build, randomly almost 2nd or 3rd sequential build, the build goes to fails because of the error message as below.

    $/teamproject/Branches/Dev/Src/xxx.xxxx.sln ('Clean' target(s)) - 1 error(s), 0 warning(s), View Log File

    C:\Program Files (x86)\MSBuild\Microsoft\WebDeployment\v10.0\Microsoft.WebDeployment.targets (794): Unable to remove directory "obj\Release\Source". The directory is not empty.

    or "obj\Release\TempBuildDir"

    So, whenever a build failed due  to the directory is not empty error, under the binaries folder at Binaires\Release\_PublishedWebsites\WDP (Web Deployment Project)\, some sub directories are not clean by the Delete Binaries work flow recursively.

    So, I put the clean task at the WDP .csproject and the actually web site application as shown as below.


    Then, the team build consistently stop giving me the directory is not empty error.

    Hope that it helps you to resolve your issue if you run into the same problem.

    Right after getting this directory is not empty issue, submitting the 2nd queue new build works fine.

    • Edited by John Roh Tuesday, October 30, 2012 4:25 PM
    Thursday, October 25, 2012 1:26 AM


All replies

  • Hi,

    you could you handle.exe to remove the handles on the directory..



    Mayank Goswami

    Thursday, October 25, 2012 8:17 AM
  • Hi John,

    Thanks for your post!

    Please make sure if there is perhaps another service or application that is touching files in the directory while the build is running?  If so, try stopping the services or closing the applications that use any file or directory from the C:\Program Files (x86)\MSBuild\Microsoft\WebDeployment\v10.0\Microsoft.WebDeployment.targets

    Hope it helps!

    Best Regards,

    Cathy Kong [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, October 25, 2012 8:58 AM
  • Thanks for replying again, Cathy.

    I don't think it's by one single reason that the issue gets invoked. I have noticed that I have updated the many exclusion lists on DiskKeeper and Symantec End Point Protection not to execute anything on the build drop locations and TFS service related users data folders and so on.

    This is such a wasting time and frustration though.

    Thursday, October 25, 2012 6:04 PM
  • Hi John,

    Did you try Handle.exe... Better create custom activity and use handle.exe to kill the handles on the build resources.


    Hope this will help...



    Mayank Goswami

    • Marked as answer by John Roh Thursday, October 25, 2012 10:21 PM
    • Unmarked as answer by John Roh Thursday, October 25, 2012 11:44 PM
    • Marked as answer by Cathy KongModerator Wednesday, October 31, 2012 9:05 AM
    Thursday, October 25, 2012 7:27 PM
  • Thank you, Mayank.

    You're correct on this but why is this keep on happening? Is there anyway that the same folder doesn't get locked again?

    Thursday, October 25, 2012 8:34 PM
  • Hi John,

    This is common issue i have been seen for years.. :) Reason sometime test team write some bad code and their test crash, leaving some process keeping hold of some of the build resources...sometime some people stop the build in between and some of the resouces get locked...

    utilities like handle.exe and unlocker.exe are often used by us...

    Mayank Goswami

    • Marked as answer by John Roh Monday, October 29, 2012 9:05 PM
    • Unmarked as answer by John Roh Tuesday, October 30, 2012 4:16 PM
    Thursday, October 25, 2012 8:43 PM
  • Mayank,

    I see, however, we never had this issue before up until we moved the build server to Windows 2008 R2. That's why I spent so many times trying to fix it but there wasn't any good solution.


    Is there any MS side official documented on this issue if this is a common issue? I have been used TFS from 2005/2008/2010 but never seen this issue before.

    • Edited by John Roh Sunday, October 28, 2012 7:34 AM
    Thursday, October 25, 2012 10:22 PM
  • Hi John,

    Thanks for your feedback!

    I would suggest you to report this issue on our Connect Portal:


    Every feedback submitted will be evaluated carefully by our engineers. If they have some feedback on it, they will let us know their comments further through that portal. This would be helpful to improve Visual Studio products.

    Best Regards,

    Cathy Kong [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 29, 2012 9:12 AM
  • Mayank,

    I'm re-opened the question again because it failed again after un-locked the folder where it caused the build goes to "Directory is not empty".

    This morning, it happens again but the folder where it caused showing "no matching handles found". Any other suggestion?

    Current behavior is "queue new build" after getting this error message works fine. 

    Best Regards,


    • Edited by John Roh Tuesday, October 30, 2012 4:24 PM
    Monday, October 29, 2012 9:06 PM
  • Hi,

    Can you please share more details on this?

    To my understanding after releasing the handle, the build still failed and gave the error "Directory is not empty"

    Also please ensure when you trigger the buid, the folder on the build server(where all sources are get from the version control) is not accessed by anyone. Even it should not be opened on the build server.




    Mayank Goswami

    • Marked as answer by John Roh Wednesday, October 31, 2012 4:32 PM
    • Unmarked as answer by John Roh Wednesday, October 31, 2012 4:32 PM
    Wednesday, October 31, 2012 1:38 PM
  • Yes, you got that correct. It's the issue I'm having with.

    Once I used handle command with -c -y -pid, it did closed handle fine. However, I have note that pretty much the same location of the sub folder doesn't get deleted completely. The frequency of the occurring issue has been dropped now. Is this normal that the same path gets locked frequently? I need to find out more consistent behavior so that I can provide further. 

    Thank you,


    Wednesday, October 31, 2012 4:38 PM
  • I observed further the issue occurs because of the Symantec Endpoint. I put some processes and folders under exclusion lists hoping the Endpoint doesn't run but it still does.

    Both build servers failed and I run "handle" on the build source and drop location that i couldn't find any locked files and folders which didn't help. 

    While I'm trying to reboot the build servers after the build failed on both build servers, I got the confirmation saying the current scan will be stopped if I reboot. After the reboot, the build runs fine. 

    Wednesday, November 14, 2012 2:00 AM
  • It appears to me that I saw lots of Creating files and query directory by Disk Keeper Service on the build drop folder and c:\users\TFSService\AppData\Local\Temp directory. While the build templates try to run to clean out processes, the DkService.exe runs at the same time which locks out the same build drop UNC path. 

    Now, i'm trying to find out the way to exclude running DkService.exe on the build related folders and paths. 

    Friday, December 28, 2012 6:01 PM
  • Did you try just stopping the Diskeeper service (dkservice) and starting it again after your process is complete?
    Wednesday, November 13, 2013 3:22 PM