Merge pull request #225 from mistoll/master
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / WriteLinesToFile.cs
index adf6418d303ff48f110002fc7ca287389a6e6690..80456985f5445ad449eae6acc462a2b211256e70 100644 (file)
@@ -48,15 +48,19 @@ namespace Microsoft.Build.Tasks {
 
                public override bool Execute ()
                {
-                       if (file == null)
-                               throw new ArgumentNullException  ("file", "File TaskItem must be set.");
-                       if (file.ItemSpec == String.Empty)
-                               throw new ArgumentException ("File must be specified in ItemSpec.");
                        try {
-                               streamWriter = new StreamWriter (file.GetMetadata ("FullPath"), !overwrite);
-                               foreach (ITaskItem line in lines) {
-                                       streamWriter.WriteLine (line);
+                               string fullpath = file.GetMetadata ("FullPath");
+                               if (lines == null && overwrite) {
+                                       System.IO.File.Delete (fullpath);
+                                       return true;
                                }
+
+                               using (streamWriter = new StreamWriter (fullpath, !overwrite)) {
+                                       if (lines != null)
+                                               foreach (ITaskItem line in lines)
+                                                       streamWriter.WriteLine (line);
+                               }
+
                                return true;
                        }
                        catch (Exception ex) {
@@ -87,4 +91,4 @@ namespace Microsoft.Build.Tasks {
        }
 }
 
-#endif
\ No newline at end of file
+#endif