forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollatePackageDownloads.cs
34 lines (30 loc) · 1.34 KB
/
CollatePackageDownloads.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
// 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 Microsoft.Build.Utilities;
namespace Microsoft.NET.Build.Tasks
{
/// <summary>
/// Multiple PackageDownload items for the same package aren't supported. Rather, to download multiple versions of the same
/// package, the PackageDownload items can have a semicolon-separated list of versions (each in brackets) as the Version metadata.
/// So this task groups a list of items with Version metadata into a list of items which can be used as PackageDownloads.
/// </summary>
public class CollatePackageDownloads : TaskBase
{
[Required]
public ITaskItem[] Packages { get; set; }
[Output]
public ITaskItem [] PackageDownloads { get; set; }
protected override void ExecuteCore()
{
PackageDownloads = Packages.GroupBy(p => p.ItemSpec)
.Select(g =>
{
var packageDownloadItem = new TaskItem(g.Key);
packageDownloadItem.SetMetadata("Version", string.Join(";",
g.Select(p => "[" + p.GetMetadata("Version") + "]")));
return packageDownloadItem;
}).ToArray();
}
}
}