forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResolveFrameworkReferences.cs
65 lines (52 loc) · 3.11 KB
/
ResolveFrameworkReferences.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Microsoft.NET.Build.Tasks
{
public class ResolveFrameworkReferences : TaskBase
{
public ITaskItem[] FrameworkReferences { get; set; } = Array.Empty<ITaskItem>();
public ITaskItem[] ResolvedTargetingPacks { get; set; } = Array.Empty<ITaskItem>();
public ITaskItem[] ResolvedRuntimePacks { get; set; } = Array.Empty<ITaskItem>();
[Output]
public ITaskItem[] ResolvedFrameworkReferences { get; set; }
protected override void ExecuteCore()
{
if (FrameworkReferences.Length == 0)
{
return;
}
var resolvedTargetingPacks = ResolvedTargetingPacks.ToDictionary(tp => tp.ItemSpec, StringComparer.OrdinalIgnoreCase);
var resolvedRuntimePacks = ResolvedRuntimePacks.ToDictionary(rp => rp.GetMetadata(MetadataKeys.FrameworkName), StringComparer.OrdinalIgnoreCase);
var resolvedFrameworkReferences = new List<TaskItem>(FrameworkReferences.Length);
foreach (var frameworkReference in FrameworkReferences)
{
ITaskItem targetingPack;
if (!resolvedTargetingPacks.TryGetValue(frameworkReference.ItemSpec, out targetingPack))
{
// FrameworkReference didn't resolve to a targeting pack
continue;
}
TaskItem resolvedFrameworkReference = new TaskItem(frameworkReference.ItemSpec);
resolvedFrameworkReference.SetMetadata(MetadataKeys.OriginalItemSpec, frameworkReference.ItemSpec);
resolvedFrameworkReference.SetMetadata(MetadataKeys.IsImplicitlyDefined, frameworkReference.GetMetadata(MetadataKeys.IsImplicitlyDefined));
resolvedFrameworkReference.SetMetadata("TargetingPackPath", targetingPack.GetMetadata(MetadataKeys.Path));
resolvedFrameworkReference.SetMetadata("TargetingPackName", targetingPack.GetMetadata(MetadataKeys.NuGetPackageId));
resolvedFrameworkReference.SetMetadata("TargetingPackVersion", targetingPack.GetMetadata(MetadataKeys.NuGetPackageVersion));
resolvedFrameworkReference.SetMetadata("Profile", targetingPack.GetMetadata("Profile"));
ITaskItem runtimePack;
if (resolvedRuntimePacks.TryGetValue(frameworkReference.ItemSpec, out runtimePack))
{
resolvedFrameworkReference.SetMetadata("RuntimePackPath", runtimePack.GetMetadata(MetadataKeys.PackageDirectory));
resolvedFrameworkReference.SetMetadata("RuntimePackName", runtimePack.GetMetadata(MetadataKeys.NuGetPackageId));
resolvedFrameworkReference.SetMetadata("RuntimePackVersion", runtimePack.GetMetadata(MetadataKeys.NuGetPackageVersion));
}
resolvedFrameworkReferences.Add(resolvedFrameworkReference);
}
ResolvedFrameworkReferences = resolvedFrameworkReferences.ToArray();
}
}
}