//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.BuildTasks { using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Build.BuildEngine; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; public class AddProjectItems : Task { /// /// Gets or sets the projects to add items to. /// /// The projects. [Required] public ITaskItem[] Projects { get; set; } /// /// Gets or sets the items to add to each project. /// /// The items. /// /// Use the metadata "ItemType" on each item to specify the item type to use for the new /// project item. If the metadata is absent, "None" is used as the item type. /// [Required] public ITaskItem[] Items { get; set; } /// /// Executes this instance. /// public override bool Execute() { foreach (var projectTaskItem in this.Projects) { var project = new Project(); project.Load(projectTaskItem.ItemSpec); foreach (var projectItem in this.Items) { string itemType = projectItem.GetMetadata("ItemType"); if (string.IsNullOrEmpty(itemType)) { itemType = "None"; } BuildItem newItem = project.AddNewItem(itemType, projectItem.ItemSpec, false); var customMetadata = projectItem.CloneCustomMetadata(); foreach (DictionaryEntry entry in customMetadata) { string value = (string)entry.Value; if (value.Length > 0) { newItem.SetMetadata((string)entry.Key, value); } } } project.Save(projectTaskItem.ItemSpec); } return !this.Log.HasLoggedErrors; } } }