forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParseTargetManifests.cs
71 lines (61 loc) · 2.95 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
65
66
67
68
69
70
71
// 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 Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.Packaging.Core;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
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)
{
Log.LogMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, Strings.ParsingFiles, manifestFile));
var packagesSpecified = StoreArtifactParser.Parse(manifestFile);
var targetManifestFileName = Path.GetFileName(manifestFile);
foreach (var pkg in packagesSpecified)
{
Log.LogMessage(MessageImportance.Low, string.Format(CultureInfo.CurrentCulture, Strings.PackageInfoLog, pkg.Id, pkg.Version));
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 TaskItem($"{packageName}/{packageVersion}");
item.SetMetadata(MetadataKeys.PackageName, packageName);
item.SetMetadata(MetadataKeys.PackageVersion, packageVersion);
item.SetMetadata(MetadataKeys.RuntimeStoreManifestNames, storeEntry.Value.ToString());
resultPackages.Add(item);
}
RuntimeStorePackages = resultPackages.ToArray();
}
}
}
}