Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
Created September 22, 2020 15:25
Show Gist options
  • Save smailliwcs/91ff65631d2840f08f33760de2de8f85 to your computer and use it in GitHub Desktop.
Save smailliwcs/91ff65631d2840f08f33760de2de8f85 to your computer and use it in GitHub Desktop.
MSBuild task: FindFilesInList
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public class FindFilesInList : Task
{
[Required]
public ITaskItem[] Items { get; set; }
[Required]
public ITaskItem[] ItemsToFind { get; set; }
[Output]
public ITaskItem[] FoundItems { get; set; }
public override bool Execute()
{
ICollection<string> pathsToFind = ItemsToFind.Select(taskItem => new FileInfo(taskItem.ItemSpec).FullName).ToList();
ICollection<ITaskItem> foundItemsList = new List<ITaskItem>();
foreach (ITaskItem item in Items)
{
FileInfo file = new FileInfo(item.ItemSpec);
if (pathsToFind.Contains(file.FullName))
{
foundItemsList.Add(item);
}
}
FoundItems = foundItemsList.ToArray();
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment