forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CollectSDKReferencesDesignTime.cs
77 lines (64 loc) · 3.02 KB
/
CollectSDKReferencesDesignTime.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
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Microsoft.NET.Build.Tasks
{
/// <summary>
/// Aggregates the sdk specified as project items and implicit packages references.
/// Note: this task is not used temporarily as a hack for RTM to be able to get all
/// implicit SDKs across all TFMs. In U1 we will switch back to this task when multiple
/// TFM support is added to Dependencies logic.
/// Tracking issue https://github.com/dotnet/roslyn-project-system/issues/587
/// </summary>
public class CollectSDKReferencesDesignTime : TaskBase
{
[Required]
public ITaskItem[] SdkReferences { get; set; }
[Required]
public ITaskItem[] PackageReferences { get; set; }
[Required]
public string DefaultImplicitPackages { get; set; }
[Output]
public ITaskItem[] SDKReferencesDesignTime { get; set; }
private HashSet<string> ImplicitPackageReferences { get; set; }
protected override void ExecuteCore()
{
ImplicitPackageReferences =
PreprocessPackageDependenciesDesignTime.GetImplicitPackageReferences(DefaultImplicitPackages);
var sdkDesignTimeList = new List<ITaskItem>(SdkReferences);
sdkDesignTimeList.AddRange(GetImplicitPackageReferences());
SDKReferencesDesignTime = sdkDesignTimeList.ToArray();
}
private IEnumerable<ITaskItem> GetImplicitPackageReferences()
{
var implicitPackages = new List<ITaskItem>();
foreach (var packageReference in PackageReferences)
{
var isImplicitlyDefined = false;
var isImplicitlyDefinedString = packageReference.GetMetadata(MetadataKeys.IsImplicitlyDefined);
if (string.IsNullOrEmpty(isImplicitlyDefinedString))
{
isImplicitlyDefined = ImplicitPackageReferences.Contains(packageReference.ItemSpec);
}
else
{
Boolean.TryParse(isImplicitlyDefinedString, out isImplicitlyDefined);
}
if (isImplicitlyDefined)
{
var newTaskItem = new TaskItem(packageReference.ItemSpec);
newTaskItem.SetMetadata(MetadataKeys.SDKPackageItemSpec, string.Empty);
newTaskItem.SetMetadata(MetadataKeys.Name, packageReference.ItemSpec);
newTaskItem.SetMetadata(MetadataKeys.IsImplicitlyDefined, "True");
newTaskItem.SetMetadata(MetadataKeys.Version, packageReference.GetMetadata(MetadataKeys.Version));
implicitPackages.Add(newTaskItem);
}
}
return implicitPackages;
}
}
}