forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParseTargetManifests.cs
64 lines (54 loc) · 2.52 KB
/
ParseTargetManifests.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
// 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;
using NuGet.Packaging.Core;
namespace Microsoft.NET.Build.Tasks
{
/// <summary>
/// Parses the target manifest files into MSBuild Items.
/// </summary>
public sealed class ParseTargetManifests : TaskBase
{
public string TargetManifestFiles { get; set; }
[Output]
public ITaskItem[] RuntimeStorePackages { get; private set; }
protected override void ExecuteCore()
{
string[] targetManifestFileList = TargetManifestFiles?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (targetManifestFileList != null && targetManifestFileList.Length > 0)
{
var runtimeStorePackages = new Dictionary<PackageIdentity, StringBuilder>();
foreach (var manifestFile in targetManifestFileList)
{
var packagesSpecified = StoreArtifactParser.Parse(manifestFile);
var targetManifestFileName = Path.GetFileName(manifestFile);
foreach (var pkg in packagesSpecified)
{
StringBuilder fileList;
if (runtimeStorePackages.TryGetValue(pkg, out fileList))
{
fileList.Append($";{targetManifestFileName}");
}
else
{
runtimeStorePackages.Add(pkg, new StringBuilder(targetManifestFileName));
}
}
}
var resultPackages = new List<ITaskItem>();
foreach (var storeEntry in runtimeStorePackages)
{
string packageName = storeEntry.Key.Id;
string packageVersion = storeEntry.Key.Version.ToNormalizedString();
TaskItem item = new($"{packageName}/{packageVersion}");
item.SetMetadata(MetadataKeys.NuGetPackageId, packageName);
item.SetMetadata(MetadataKeys.NuGetPackageVersion, packageVersion);
item.SetMetadata(MetadataKeys.RuntimeStoreManifestNames, storeEntry.Value.ToString());
resultPackages.Add(item);
}
RuntimeStorePackages = resultPackages.ToArray();
}
}
}
}