forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindItemsFromPackages.cs
46 lines (39 loc) · 1.48 KB
/
FindItemsFromPackages.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Build.Framework;
using NuGet.Packaging.Core;
namespace Microsoft.NET.Build.Tasks
{
/// <summary>
/// Returns the ITaskItem values in Items that were resolved from the specified
/// set of Packages.
/// </summary>
/// <remarks>
/// Both Items and Packages are expected to have 'NuGetPackageId' and 'NuGetPackageVersion'
/// metadata properties to use for the matching.
/// </remarks>
public sealed class FindItemsFromPackages : TaskBase
{
[Required]
public ITaskItem[] Items { get; set; }
[Required]
public ITaskItem[] Packages { get; set; }
[Output]
public ITaskItem[] ItemsFromPackages { get; private set; }
protected override void ExecuteCore()
{
var packageIdentities = new HashSet<PackageIdentity>(
Packages.Select(p => ItemUtilities.GetPackageIdentity(p)));
var itemsFromPackages = new List<ITaskItem>();
foreach (ITaskItem item in Items)
{
PackageIdentity identity = ItemUtilities.GetPackageIdentity(item);
if (identity != null && packageIdentities.Contains(identity))
{
itemsFromPackages.Add(item);
}
}
ItemsFromPackages = itemsFromPackages.ToArray();
}
}
}