forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckForImplicitPackageReferenceOverrides.cs
41 lines (33 loc) · 1.35 KB
/
CheckForImplicitPackageReferenceOverrides.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
using Microsoft.Build.Framework;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
namespace Microsoft.NET.Build.Tasks
{
public class CheckForImplicitPackageReferenceOverrides : TaskBase
{
const string MetadataKeyForItemsToRemove = "IsImplicitlyDefined";
[Required]
public ITaskItem [] PackageReferenceItems { get; set; }
[Required]
public string MoreInformationLink { get; set; }
[Output]
public ITaskItem[] ItemsToRemove { get; set; }
protected override void ExecuteCore()
{
var duplicateItems = PackageReferenceItems.GroupBy(i => i.ItemSpec, StringComparer.OrdinalIgnoreCase).Where(g => g.Count() > 1);
var duplicateItemsToRemove = duplicateItems.SelectMany(g => g.Where(
item => item.GetMetadata(MetadataKeyForItemsToRemove).Equals("true", StringComparison.OrdinalIgnoreCase)));
ItemsToRemove = duplicateItemsToRemove.ToArray();
foreach (var itemToRemove in ItemsToRemove)
{
string message = string.Format(CultureInfo.CurrentCulture, Strings.PackageReferenceOverrideWarning,
itemToRemove.ItemSpec,
MoreInformationLink);
Log.LogWarning(message);
}
}
}
}