RemoveDir Locking the Folder with UNC Path
I am using Team Build to deploy our Dev Environment, We were doing fine with websites and Web Application projects. But I am having issues when I am deploying Windows Services or SSIS packages. When I am deploying, I am making sure through MSBuild script that the Windows services are stopped. But still when I use "RemoveDir" to delete the service directory, it is some times locking up the folder and I get "Access denied" message. That time, I have to restart the system to get rid of the folder. This is happenning more if the service is heavily used by many users (although I choose a time when service is less utilized or not utilized). I am sure the service is stopped and I tried uninstalling the service also before removing the folder. But still I can't do reliable deployment out of the team build.
I have written separate MSBuild scripts to execute the same script to run on the target server directly instead of a team build deploys properly the files. Not sure what I am doing wrong. Anybody got any similar errors?
The error log displays this :
Task "RemoveDir"
Removing directory "\\DevServer\Services\TickerService\bin".
Command:
rd /s /q "\\DevServer\Services\TickerService\bin"
d:\bld\TestProj\DEV-TickerService\BuildType\TFSBuild.proj(397,5): error MSB3231: Unable to remove directory "\\DevServer\Services\TickerService\bin". Access to the path '\\DevServer\Services\TickerService\bin' is denied.
Done executing task "RemoveDir" -- FAILED.
Answers
- Hello rtandra,
Thanks for your post.
We'd better first find out which process locks the UNC path. Since it is a net share folder, it can also be locked by remote machine. I have made out an action plan to find out the process, if you can reproduce the error. Here are the steps:
1. After the issue occurs (the path is locked), logon to DevServer machine and execute Handle.exe tool with command line:
handle TickerService\bin
Check if there is any local process which locks the path.
2. If there is no local process, please run the tool: NetShare Monitor and check if there is any remote machine which locks the path. You can see remote machine's IP address from the tool
3. Go to the remote machine which is found out from previous step, and execute following command:
handle -a TickerService\bin
Check what process locks the UNC path.
The issue may be caused by multiple processes execution in team build. Can you help to check if you have set MaxProcesses to more than 1 in TFS build machine?
Hope it helps & Have a nice day.
Hongye Sun [MSFT]
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg @ microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byrtandra 1 hour 23 minutes ago
- Hi Ravi,
Thanks for your feedback.
I doesn't know any existing method to prevent this issue.
One possible way is to write a custom task to delete the folder programmatically.
The code logic will be:
1. Try to delete the folder with Try...Catch block;
2. If it catches IOException, wait for a time period then go to step 1;
You can make the custom task to be configurable for wait time period and retry times limit.
Hope it helps.
Hongye Sun [MSFT]
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg @ microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byrtandra 1 hour 22 minutes ago
- I'm guessing the bin folder is empty, so what you could do is use the MSBuild Extension Pack Folder-RemoveContent task to remove everything from bin, but leave the folder behind.
< MSBuild.ExtensionPack.FileSystem.Folder TaskAction = "RemoveContent" Path = " \\DevServer\Services\TickerService\bin" />
Would be better to find out what has the handle, but it's another option for you.
Mike- Proposed As Answer byMike Fourie Monday, November 23, 2009 7:36 PM
- Marked As Answer byrtandra 1 hour 23 minutes ago
All Replies
- Hello rtandra,
Thanks for your post.
We'd better first find out which process locks the UNC path. Since it is a net share folder, it can also be locked by remote machine. I have made out an action plan to find out the process, if you can reproduce the error. Here are the steps:
1. After the issue occurs (the path is locked), logon to DevServer machine and execute Handle.exe tool with command line:
handle TickerService\bin
Check if there is any local process which locks the path.
2. If there is no local process, please run the tool: NetShare Monitor and check if there is any remote machine which locks the path. You can see remote machine's IP address from the tool
3. Go to the remote machine which is found out from previous step, and execute following command:
handle -a TickerService\bin
Check what process locks the UNC path.
The issue may be caused by multiple processes execution in team build. Can you help to check if you have set MaxProcesses to more than 1 in TFS build machine?
Hope it helps & Have a nice day.
Hongye Sun [MSFT]
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg @ microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byrtandra 1 hour 23 minutes ago
- This is a tricky problem. I tried this for several times to repeat this problem. When I get this problem I tried to login and run the Handle/NetShareMon but there was no locks, and when I run the build again it deploys it properly. Unfortunately, this time always I got as "Unaccesed Directory" but it didn't get to the dead lock situation where we have to restart the system. If I could have got that problem may would have known which process locked it.
This problem is not repeating when we deploy locally using MSBuild scripts. I am sure that some of the process may be the SSIS packages that I am deploying is in access by SQL server and is not allowing to delete the folder. By the time I execute the Handle.exe the process might have released lock. The other place i got this error with Windows Services, when I specified Service Stop it would have taken some more time to unload the files, mean while msbuild tries to copy files it gets access denied. When I gave some 1min/2min wait then it is working fine.
There should be something to ensure from MSBuild to know if a folder is ready to be deleted. I am sure there must be lot of peopl dealing with Windows Services/SSIS packages and probably using Team build to deploy to dev/qa servers. Any comments or suggestions?
Thanks,
Ravi - Hi Ravi,
Thanks for your feedback.
I doesn't know any existing method to prevent this issue.
One possible way is to write a custom task to delete the folder programmatically.
The code logic will be:
1. Try to delete the folder with Try...Catch block;
2. If it catches IOException, wait for a time period then go to step 1;
You can make the custom task to be configurable for wait time period and retry times limit.
Hope it helps.
Hongye Sun [MSFT]
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg @ microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byrtandra 1 hour 22 minutes ago
- I'm guessing the bin folder is empty, so what you could do is use the MSBuild Extension Pack Folder-RemoveContent task to remove everything from bin, but leave the folder behind.
< MSBuild.ExtensionPack.FileSystem.Folder TaskAction = "RemoveContent" Path = " \\DevServer\Services\TickerService\bin" />
Would be better to find out what has the handle, but it's another option for you.
Mike- Proposed As Answer byMike Fourie Monday, November 23, 2009 7:36 PM
- Marked As Answer byrtandra 1 hour 23 minutes ago
Hi Ravi,
Is this issue resolved? Please feel free to let me know if you need any further help. Thanks.
Hongye Sun [MSFT]
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg @ microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- I was not able to reproduce this after wards. May be it might have resolved by itself or it is a other environment issue. I know this has occured previously. I will close this thread. In future If I get anything I will open the thread again. Thanks for your feedback.


