Hi All,

I've made a quick patch to add a clean action to the solution task.
Basically it will remove all the primary output files.  I would like some
feedback on this.

<solution solutionfile="WindowsApplication.sln" configuration="debug"
action="Clean" >
</solution>

Cheers,

Eddie

? patch.txt
Index: ConfigurationSettings.cs
===================================================================
RCS file: /cvsroot/nant/nant/src/NAnt.VSNet/ConfigurationSettings.cs,v
retrieving revision 1.10
diff -u -r1.10 ConfigurationSettings.cs
--- ConfigurationSettings.cs    27 Aug 2003 16:55:10 -0000      1.10
+++ ConfigurationSettings.cs    6 Sep 2003 14:27:04 -0000
@@ -19,6 +19,7 @@
 using System.Globalization;
 using System.IO;
 using System.Collections;
+using System.Collections.Specialized;
 using System.Xml;
 
 using NAnt.Core;
@@ -66,6 +67,13 @@
                 Directory.CreateDirectory(Path.GetDirectoryName(_docFilename));
             }
 
+            string debugValue;
+            if (!StringUtils.IsNullOrEmpty(debugValue = 
elemConfig.GetAttribute("DebugSymbols"))) {
+                if (debugValue == "true") {
+                    _pdbFilename = Path.Combine(_outputPath, 
this._projectSettings.Name + ".pdb");
+                }
+            }
+
             _solutionTask.Log(Level.Debug, _solutionTask.LogPrefix + "Project: {0} 
Relative Output Path: {1} Output Path: {2} Documentation Path: {3}", 
                 projectSettings.Name, _relativeOutputPath, _outputPath, _docFilename);
 
@@ -115,11 +123,19 @@
 
         public string[] ExtraOutputFiles {
             get {
-                if (_docFilename == null) {
-                    return new string[0];
+                StringCollection extraFiles = new StringCollection();
+
+                if (_docFilename != null) {
+                    extraFiles.Add(_docFilename);
+                }
+
+                if (_pdbFilename != null) {
+                    extraFiles.Add(_pdbFilename);
                 }
 
-                return new string[] {_docFilename};
+                string[] extraFilesArray = new string[extraFiles.Count];
+                extraFiles.CopyTo(extraFilesArray, 0);
+                return extraFilesArray;
             }
         }
 
@@ -149,6 +165,7 @@
 
         private ArrayList _settings;
         private string _docFilename;
+        private string _pdbFilename;
         private string _relativeOutputPath;
         private string _outputPath;
         private string _name;
Index: Project.cs
===================================================================
RCS file: /cvsroot/nant/nant/src/NAnt.VSNet/Project.cs,v
retrieving revision 1.17
diff -u -r1.17 Project.cs
--- Project.cs  2 Sep 2003 18:52:29 -0000       1.17
+++ Project.cs  6 Sep 2003 14:27:06 -0000
@@ -234,6 +234,34 @@
             }
         }
 
+        public bool Clean(string configuration) {
+            ConfigurationSettings cs = (ConfigurationSettings) 
_htConfigurations[configuration];
+            if (cs == null) {
+                Log(Level.Info, _solutionTask.LogPrefix + "Configuration {0} does not 
exist, skipping.", configuration);
+                return true;
+            }
+
+            // Setup delete task
+            DeleteTask dt = new DeleteTask();
+            dt.InitializeTaskConfiguration();
+            dt.Project = this._solutionTask.Project;
+            dt.FailOnError = false;
+            dt.Verbose = this._solutionTask.Verbose;
+
+            // Clean primary output
+            dt.DeleteFileSet.FileNames.Add(cs.FullOutputFile);
+
+            // Clean extra output
+            foreach (string file in cs.ExtraOutputFiles) {
+                dt.DeleteFileSet.FileNames.Add(file);
+            }
+
+            // Execute delete task
+            dt.Execute();
+            
+            return true;
+        }
+
         public bool Compile(string configuration, ArrayList alCSCArguments, string 
strLogFile, bool bVerbose, bool bShowCommands) {
             bool bSuccess = true;
 
Index: Solution.cs
===================================================================
RCS file: /cvsroot/nant/nant/src/NAnt.VSNet/Solution.cs,v
retrieving revision 1.13
diff -u -r1.13 Solution.cs
--- Solution.cs 2 Sep 2003 19:01:33 -0000       1.13
+++ Solution.cs 6 Sep 2003 14:27:08 -0000
@@ -49,13 +49,13 @@
 
             string fileContents;
 
-            using (StreamReader sr = new StreamReader(solutionFileName)) {
+            using (StreamReader sr = new StreamReader(_solutionTask.SolutionFile)) {
                 fileContents = sr.ReadToEnd();
             }
 
             Regex re = new 
Regex(@"Project\(\""(?<package>\{.*?\})\"".*?\""(?<name>.*?)\"".*?\""(?<project>.*?)\"".*?\""(?<guid>.*?)\""");
             MatchCollection mc = re.Matches(fileContents);
-            FileInfo fiSolution = new FileInfo(solutionFileName);
+            FileInfo fiSolution = new FileInfo(_solutionTask.SolutionFile);
 
             foreach (Match m in mc) {
                 string project = m.Groups["project"].Value;
@@ -181,6 +181,16 @@
 
         public Project GetProjectFromGUID(string projectGUID) {
             return (Project) _htProjects[projectGUID];
+        }
+
+        public bool Clean(string configuration, string logFile, bool verbose, bool 
showCommands) {
+            foreach (Project p in _htProjects.Values) {
+                if (!p.Clean(configuration)) {
+                    return false;
+                }
+            }
+
+            return true;
         }
 
         public bool Compile(string configuration, ArrayList compilerArguments, string 
logFile, bool verbose, bool showCommands) {
Index: Tasks/SolutionTask.cs
===================================================================
RCS file: /cvsroot/nant/nant/src/NAnt.VSNet/Tasks/SolutionTask.cs,v
retrieving revision 1.12
diff -u -r1.12 SolutionTask.cs
--- Tasks/SolutionTask.cs       4 Sep 2003 16:50:33 -0000       1.12
+++ Tasks/SolutionTask.cs       6 Sep 2003 14:27:08 -0000
@@ -127,6 +127,7 @@
             _excludeProjects = new FileSet();
             _assemblyFolders = new FileSet();
             _webMaps = new WebMapCollection();
+                       _actionType = ActionType.Build;
         }
 
         #endregion Public Instance Constructors
@@ -219,6 +220,13 @@
             set { _excludeProjects = value; }
         }
 
+               [TaskAttribute("action", Required=false)]
+               public ActionType Action
+               {
+                       get { return _actionType; }
+                       set { _actionType = value; }
+               }
+
         /// <summary>
         /// Set of folders where references are searched when not found in path 
         /// from project file (HintPath).
@@ -276,7 +284,7 @@
                     Log(Level.Verbose, LogPrefix + " - " + projectFile);
                 }
             }
-            
+
             string basePath = null;
 
             try {
@@ -289,9 +297,20 @@
                             new ArrayList(ReferenceProjects.FileNames), tfc, this, 
WebMaps, ExcludeProjects, OutputDir);
                     }
 
-                    if (!sln.Compile(Configuration, new ArrayList(), null, Verbose, 
false)) {
-                        throw new BuildException("Project build failed.", Location);
-                    }
+                                       if (Action == ActionType.Build)
+                                       {
+                                               if (!sln.Compile(Configuration, new 
ArrayList(), null, Verbose, false)) 
+                                               {
+                                                       throw new 
BuildException("Project build failed.", Location);
+                                               }
+                                       }
+                                       else if (Action == ActionType.Clean)
+                                       {
+                                               if (!sln.Clean(Configuration, null, 
Verbose, false)) 
+                                               {
+                                                       throw new 
BuildException("Project clean failed.", Location);
+                                               }
+                                       }
                 
                     basePath = tfc.BasePath;
                 }
@@ -374,7 +393,7 @@
         private FileSet _assemblyFolders;
         private WebMapCollection _webMaps;
         private bool _includeVSFolders;
-
+        private ActionType _actionType;
 
         #endregion Private Instance Fields
 
@@ -384,5 +403,10 @@
         private const string VS70AssemblyFolders = 
@"SOFTWARE\Microsoft\VisualStudio\7.0\AssemblyFolders";
 
         #endregion Private Static Fields
+    }
+
+    public enum ActionType {
+        Build,
+        Clean
     }
 }

Reply via email to