Created
September 22, 2020 15:25
-
-
Save smailliwcs/91ff65631d2840f08f33760de2de8f85 to your computer and use it in GitHub Desktop.
MSBuild task: FindFilesInList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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