// 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.Generic;
+using System.IO;
using Microsoft.Build.Framework;
namespace Microsoft.Build.Tasks {
string[] additionalMetadata;
ITaskItem[] exclude;
ITaskItem[] include;
-
+ bool preserveExistingMetadata;
+
public CreateItem ()
{
}
public override bool Execute ()
{
- throw new NotImplementedException ();
+ if (include == null || include.Length == 0)
+ return true;
+
+ // Handle wild cards
+ var directoryScanner = new Microsoft.Build.BuildEngine.DirectoryScanner ();
+ directoryScanner.Includes = include;
+ directoryScanner.Excludes = exclude;
+ directoryScanner.BaseDirectory = new DirectoryInfo (Directory.GetCurrentDirectory ());
+
+ directoryScanner.Scan ();
+
+ List<ITaskItem> output = new List<ITaskItem> ();
+ foreach (ITaskItem matchedItem in directoryScanner.MatchedItems) {
+ output.Add (matchedItem);
+ if (AdditionalMetadata == null)
+ continue;
+
+ foreach (string metadata in AdditionalMetadata) {
+ //a=1
+ string [] parts = metadata.Split (new char [] {'='}, 2, StringSplitOptions.RemoveEmptyEntries);
+ if (parts.Length == 2) {
+ string name = parts [0].Trim ();
+ string oldValue = matchedItem.GetMetadata (name);
+ if (!preserveExistingMetadata || string.IsNullOrEmpty (oldValue))
+ matchedItem.SetMetadata (name, parts [1].Trim ());
+ }
+ }
+ }
+
+ include = output.ToArray ();
+
+ return true;
}
public string[] AdditionalMetadata {
get { return include; }
set { include = value; }
}
+
+ public bool PreserveExistingMetadata {
+ get { return preserveExistingMetadata; }
+ set { preserveExistingMetadata = value; }
+ }
}
}
-#endif