Merge pull request #2903 from krytarowski/netbsd-support-4
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / WriteLinesToFile.cs
index adf6418d303ff48f110002fc7ca287389a6e6690..a11d088a85bb2ead033df012cbef8341f6bffd97 100644 (file)
@@ -25,7 +25,6 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-#if NET_2_0
 
 using System;
 using System.Collections;
@@ -48,15 +47,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 +90,3 @@ namespace Microsoft.Build.Tasks {
        }
 }
 
-#endif
\ No newline at end of file