using Microsoft.Build.Framework; using Microsoft.Build.Utilities; public class MyTask : Task { [Required] public ITaskItem MyItem { get; set; } public override bool Execute() { string myMetadataValue = MyItem.GetMetadata("MyMetadata"); Log.LogMessage($"The value of MyMetadata is {myMetadataValue}"); return true; } }
using Microsoft.Build.Framework; public class MyTask { public ITaskItem CreateMyItem(string path) { var item = new TaskItem(path); item.SetMetadata("MyMetadata", "MyValue"); return item; } }This example shows how to create a new task item using the TaskItem class and set a metadata value. Both examples use the Microsoft.Build.Framework package library which is included with the Visual Studio SDK and can also be downloaded via NuGet.