[xbuild] RemoveDir - remove only if the dir exists.
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / RemoveDir.cs
index f1aaac7f1c03da0042ee564a71b0e3a948927108..32505c9a42474e75607b634af19b255eeab69f36 100644 (file)
@@ -45,15 +45,18 @@ namespace Microsoft.Build.Tasks {
 
                public override bool Execute ()
                {
+                       if (directories.Length == 0)
+                               return true;
+
                        List <ITaskItem> temporaryRemovedDirectories = new List <ITaskItem> ();
                        
                        foreach (ITaskItem directory in directories) {
                                try {
-                                       Directory.Delete (directory.GetMetadata ("FullPath"), true);
-                                       temporaryRemovedDirectories.Add (directory);
-                               }
-                               catch (DirectoryNotFoundException ex) {
-                                       Log.LogErrorFromException (ex);
+                                       string fullpath = directory.GetMetadata ("FullPath");
+                                       if (Directory.Exists (fullpath)) {
+                                               Directory.Delete (fullpath, true);
+                                               temporaryRemovedDirectories.Add (directory);
+                                       }
                                }
                                catch (PathTooLongException ex) {
                                        Log.LogErrorFromException (ex);
@@ -102,4 +105,4 @@ namespace Microsoft.Build.Tasks {
        }
 }
 
-#endif
\ No newline at end of file
+#endif