forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckIfPackageReferenceShouldBeFrameworkReference.cs
39 lines (31 loc) · 1.35 KB
/
CheckIfPackageReferenceShouldBeFrameworkReference.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
// 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;
namespace Microsoft.NET.Build.Tasks
{
public sealed class CheckIfPackageReferenceShouldBeFrameworkReference : TaskBase
{
public ITaskItem[] PackageReferences { get; set; } = Array.Empty<ITaskItem>();
public ITaskItem[] FrameworkReferences { get; set; } = Array.Empty<ITaskItem>();
public string PackageReferenceToReplace { get; set; }
public string FrameworkReferenceToUse { get; set; }
[Output]
public bool ShouldRemovePackageReference { get; set; }
[Output]
public bool ShouldAddFrameworkReference { get; set; }
protected override void ExecuteCore()
{
foreach (var packageReference in PackageReferences)
{
if (packageReference.ItemSpec.Equals(PackageReferenceToReplace, StringComparison.OrdinalIgnoreCase))
{
ShouldRemovePackageReference = true;
if (!FrameworkReferences.Any(fr => fr.ItemSpec.Equals(FrameworkReferenceToUse, StringComparison.OrdinalIgnoreCase)))
{
ShouldAddFrameworkReference = true;
}
}
}
}
}
}