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
RemoveDirtask after theDeleteaction has been run by usingDependsOnTargets:However it’s probable that timing is not the real issue here. The issue may be that
DeleteFilesfails to delete some locked or read-only files, which as a result fails theRemoveDirtask to complete.In this case consider using MSBuild Extension Pack’s Folder class which can forcefully remove all files.