I am using MSBuild and have a Delete task that deletes all the files under a directory. The next task cleans out the directory of any folder by using RemoveDir. I have a timing issue where the directory isn't always completely clean of files from the Delete command before the RemoveDir command runs. Happens about half the time, and when it does the script errors out, b/c the RemoveDir can't remove directories for which files exist in them.
Can someone help me with a way to fix this problem?
Make sure you are calling the RemoveDir
task after the Delete
action has been run by using DependsOnTargets
:
<Target Name="RemoveDirectories" DependsOnTargets="DeleteFiles">
<RemoveDir Directories="@(DirsToRemove)" />
</Target>
However it's probable that timing is not the real issue here. The issue may be that DeleteFiles
fails to delete some locked or read-only files, which as a result fails the RemoveDir
task to complete.
In this case consider using MSBuild Extension Pack's Folder class which can forcefully remove all files.
<MSBuild.ExtensionPack.FileSystem.Folder TaskAction="RemoveContent" Path="@(DirsToRemove)" Force="true" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With