Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

waiting for MSBuild Delete to complete

Tags:

msbuild

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?

like image 247
John Livermore Avatar asked Oct 08 '22 19:10

John Livermore


1 Answers

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" />
like image 127
KMoraz Avatar answered Oct 12 '22 11:10

KMoraz