forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PreprocessPackageDependenciesDesignTime.cs
725 lines (623 loc) · 28.7 KB
/
PreprocessPackageDependenciesDesignTime.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
// 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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Microsoft.NET.Build.Tasks
{
/// <summary>
/// Task combines data returned from ResolvePackageDependencies into single items collection
/// that can be consumed by DesignTime build and contains all info needed to expand packages
/// dependency graph.
/// If any changes are made here, make sure corresponding changes are made to NuGetDependenciesSubTreeProvider
/// in roslyn-project-system repo and corresponding tests.
/// </summary>
public class PreprocessPackageDependenciesDesignTime : TaskBase
{
public const string DependenciesMetadata = "Dependencies";
public const string CompileTimeAssemblyMetadata = "CompileTimeAssembly";
public const string ResolvedMetadata = "Resolved";
public const string VisibleMetadata = "Visible";
[Required]
public ITaskItem[] TargetDefinitions { get; set; }
[Required]
public ITaskItem[] PackageDefinitions { get; set; }
[Required]
public ITaskItem[] FileDefinitions { get; set; }
[Required]
public ITaskItem[] PackageDependencies { get; set; }
[Required]
public ITaskItem[] FileDependencies { get; set; }
[Required]
public string DefaultImplicitPackages { get; set; }
[Required]
public ITaskItem[] References { get; set; }
[Required]
public string TargetFrameworkMoniker { get; set; }
public ITaskItem[] InputDiagnosticMessages { get; set; }
[Output]
public ITaskItem[] DependenciesDesignTime { get; set; }
private Dictionary<string, ItemMetadata> Targets { get; set; }
= new Dictionary<string, ItemMetadata>(StringComparer.OrdinalIgnoreCase);
private Dictionary<string, ItemMetadata> Packages { get; set; }
= new Dictionary<string, ItemMetadata>(StringComparer.OrdinalIgnoreCase);
private Dictionary<string, ItemMetadata> Assemblies { get; set; }
= new Dictionary<string, ItemMetadata>(StringComparer.OrdinalIgnoreCase);
private Dictionary<string, ItemMetadata> DiagnosticsMap { get; set; }
= new Dictionary<string, ItemMetadata>(StringComparer.OrdinalIgnoreCase);
private Dictionary<string, ItemMetadata> DependenciesWorld { get; set; }
= new Dictionary<string, ItemMetadata>(StringComparer.OrdinalIgnoreCase);
private HashSet<string> ImplicitPackageReferences { get; set; }
private ITaskItem[] ExistingReferenceItemDependencies { get; set; }
protected override void ExecuteCore()
{
ImplicitPackageReferences = GetImplicitPackageReferences(DefaultImplicitPackages);
PopulateTargets();
PopulatePackages();
PopulateAssemblies();
PopulateExistingReferenceItems();
InputDiagnosticMessages = InputDiagnosticMessages ?? Array.Empty<ITaskItem>();
PopulateDiagnosticsMap();
AddDependenciesToTheWorld(Packages, PackageDependencies);
AddDependenciesToTheWorld(Assemblies, FileDependencies, (item) =>
{
// We keep analyzers and assemblies with CompileTimeAssembly metadata; skip everything else.
ItemMetadata itemMetadata = null;
if (Assemblies.TryGetValue(item.ItemSpec, out itemMetadata) &&
itemMetadata.Type == DependencyType.AnalyzerAssembly)
{
return false;
}
var fileGroup = item.GetMetadata(MetadataKeys.FileGroup);
return string.IsNullOrEmpty(fileGroup) || !fileGroup.Equals(CompileTimeAssemblyMetadata);
});
AddDependenciesToTheWorld(Assemblies, ExistingReferenceItemDependencies);
AddDependenciesToTheWorld(DiagnosticsMap, InputDiagnosticMessages);
// prepare output collection: add corresponding metadata to ITaskItem based in item type
DependenciesDesignTime = DependenciesWorld.Select(itemKvp =>
{
var newTaskItem = new TaskItem(itemKvp.Key);
foreach(var metadataKvp in itemKvp.Value.ToDictionary())
{
newTaskItem.SetMetadata(metadataKvp.Key, metadataKvp.Value);
}
return newTaskItem;
}).ToArray();
}
/// <summary>
/// Adds targets from TargetDefinitions to dependencies world dictionary
/// </summary>
private void PopulateTargets()
{
foreach (var targetDef in TargetDefinitions)
{
if (string.IsNullOrEmpty(targetDef.ItemSpec) || targetDef.ItemSpec.Contains("/"))
{
// skip "target/rid"s and only consume actual targets
continue;
}
var dependencyType = GetDependencyType(targetDef.GetMetadata(MetadataKeys.Type));
if (dependencyType != DependencyType.Target)
{
// keep only targets here
continue;
}
var target = new TargetMetadata(targetDef);
Targets[targetDef.ItemSpec] = target;
// add target to the world now, since it does not have parents
DependenciesWorld[targetDef.ItemSpec] = target;
}
}
/// <summary>
/// Adds packages from PackageDefinitions to the dependencies world dictionary.
/// </summary>
private void PopulatePackages()
{
foreach (var packageDef in PackageDefinitions)
{
var dependencyType = GetDependencyType(packageDef.GetMetadata(MetadataKeys.Type));
if (dependencyType != DependencyType.Package &&
dependencyType != DependencyType.Unresolved)
{
// we ignore all other dependency types since
// - assemblies we handle separatelly below
// - projects we don't care here, since they are sent to project system via other route
continue;
}
var dependency = new PackageMetadata(packageDef);
dependency.IsImplicitlyDefined = ImplicitPackageReferences.Contains(dependency.Name);
Packages[packageDef.ItemSpec] = dependency;
}
}
/// <summary>
/// Adds assemblies, analyzers and framework assemblies from FileDefinitons to dependencies world dictionary.
/// </summary>
private void PopulateAssemblies()
{
foreach (var fileDef in FileDefinitions)
{
var dependencyType = GetDependencyType(fileDef.GetMetadata(MetadataKeys.Type));
if (dependencyType != DependencyType.Assembly &&
dependencyType != DependencyType.FrameworkAssembly &&
dependencyType != DependencyType.AnalyzerAssembly)
{
continue;
}
var name = Path.GetFileName(fileDef.ItemSpec);
var assembly = new AssemblyMetadata(dependencyType, fileDef, name);
Assemblies[fileDef.ItemSpec] = assembly;
}
}
/// <summary>
/// Update FileDefinitions and FileDependencies to pretend that certain Reference items
/// explicitly added by a .targets file in the NETStandard.Library are actually normal
/// package items. This allows them to show up properly under the "SDK" node in Solution
/// Explorer, rather than just under the "Assemblies" node.
///
/// This is not meant to be a general mechanism for injecting files that can't be handled
/// through the normal NuGet package mechanisms.
/// </summary>
private void PopulateExistingReferenceItems()
{
var existingReferenceItemDependencies = new List<ITaskItem>();
foreach (var reference in References)
{
var packageName = reference.GetMetadata("NuGetPackageId");
var packageVersion = reference.GetMetadata("NuGetPackageVersion");
// This is not a "pre-resolved" assembly; skip it.
if (packageName == null || packageVersion == null)
{
continue;
}
// If we don't know about the specified package, skip it.
var packageId = $"{packageName}/{packageVersion}";
if (!Packages.TryGetValue(packageId, out ItemMetadata packageItemMetadata))
{
continue;
}
// If the file isn't actually a part of the package, skip it.
var packageMetadata = (PackageMetadata)packageItemMetadata;
if (!reference.ItemSpec.StartsWith(packageMetadata.Path, StringComparison.OrdinalIgnoreCase))
{
continue;
}
var referenceRelativePath = reference.ItemSpec.Substring(packageMetadata.Path.Length).Trim('\\');
var referenceKey = $"{packageId}/{referenceRelativePath.Replace('\\', '/')}";
// If we already know about the assembly file, skip it.
if (Assemblies.TryGetValue(referenceKey, out ItemMetadata assemblyItemMetadata))
{
continue;
}
// Create the appropriate metadata.
var name = Path.GetFileName(referenceKey);
var facadeMetadata = reference.GetBooleanMetadata("Facade");
var visible = facadeMetadata.HasValue ? !facadeMetadata.Value : true;
var assembly = new ExistingReferenceItemMetadata(name, reference.ItemSpec, visible);
Assemblies[referenceKey] = assembly;
// Create the file dependency.
existingReferenceItemDependencies.Add(new ExistingReferenceItemDependency(
referenceKey,
TargetFrameworkMoniker,
packageId));
}
ExistingReferenceItemDependencies = existingReferenceItemDependencies.ToArray();
}
private void PopulateDiagnosticsMap()
{
foreach (var diagnostic in InputDiagnosticMessages)
{
var metadata = new DiagnosticMetadata(diagnostic);
DiagnosticsMap[diagnostic.ItemSpec] = metadata;
}
}
private DependencyType GetDependencyType(string dependencyTypeString)
{
var dependencyType = DependencyType.Unknown;
if (!string.IsNullOrEmpty(dependencyTypeString))
{
Enum.TryParse(dependencyTypeString, /* ignoreCase */ true, out dependencyType);
}
return dependencyType;
}
private void AddDependenciesToTheWorld(Dictionary<string, ItemMetadata> items,
ITaskItem[] itemDependencies,
Func<ITaskItem, bool> shouldSkipItemCheck = null)
{
foreach (var dependency in itemDependencies)
{
var currentItemId = dependency.ItemSpec;
if (!items.Keys.Contains(currentItemId))
{
// if this package definition does not even exist - skip it
continue;
}
if (shouldSkipItemCheck != null && shouldSkipItemCheck(dependency))
{
continue;
}
var parentTargetId = dependency.GetMetadata(MetadataKeys.ParentTarget) ?? string.Empty;
if (parentTargetId.Contains("/") || !Targets.Keys.Contains(parentTargetId))
{
// skip "target/rid"s and only consume actual targets and ignore non-existent parent targets
continue;
}
var parentPackageId = dependency.GetMetadata(MetadataKeys.ParentPackage) ?? string.Empty;
if (!string.IsNullOrEmpty(parentPackageId) && !Packages.Keys.Contains(parentPackageId))
{
// ignore non-existent parent packages
continue;
}
var currentPackageUniqueId = $"{parentTargetId}/{currentItemId}";
// add current package to dependencies world
var currentItem = GetItem(items, currentItemId);
DependenciesWorld[currentPackageUniqueId] = currentItem;
// update parent
var parentDependencyId = $"{parentTargetId}/{parentPackageId}".Trim('/');
ItemMetadata parentDependency = null;
if (DependenciesWorld.TryGetValue(parentDependencyId, out parentDependency))
{
parentDependency.Dependencies.Add(currentItemId);
if (parentDependency.Type == DependencyType.Target)
{
currentItem.IsTopLevelDependency = true;
}
}
else
{
// Update parent's Dependencies count and make sure parent is in the dependencies world
if (!string.IsNullOrEmpty(parentPackageId))
{
parentDependency = GetItem(Packages, parentPackageId);
}
else
{
parentDependency = GetItem(Targets, parentTargetId);
currentItem.IsTopLevelDependency = true;
}
parentDependency.Dependencies.Add(currentItemId);
DependenciesWorld[parentDependencyId] = parentDependency;
}
}
}
private ItemMetadata GetItem(Dictionary<string, ItemMetadata> items, string id)
{
return Targets.Count > 1 ? items[id].Clone() : items[id];
}
private abstract class ItemMetadata
{
public ItemMetadata(DependencyType type, IList<string> dependencies = null, bool isTopLevelDependency = false)
{
Type = type;
Dependencies = dependencies == null ? new List<string>() : new List<string>(dependencies);
IsTopLevelDependency = isTopLevelDependency;
}
public DependencyType Type { get; protected set; }
public bool IsTopLevelDependency { get; set; }
/// <summary>
/// A list of name/version strings to specify dependency identities.
/// Note: identity here is just a "name/version" and does not have TFM part in front.
/// </summary>
public IList<string> Dependencies { get; }
/// <summary>
/// Returns name/value pairs for metadata specific to given item type's implementation.
/// </summary>
/// <returns></returns>
public abstract IDictionary<string, string> ToDictionary();
/// <summary>
/// Creates a copy of the item
/// </summary>
public abstract ItemMetadata Clone();
}
private class TargetMetadata : ItemMetadata
{
public TargetMetadata(ITaskItem item)
:base(DependencyType.Target)
{
RuntimeIdentifier = item.GetMetadata(MetadataKeys.RuntimeIdentifier) ?? string.Empty;
TargetFrameworkMoniker = item.GetMetadata(MetadataKeys.TargetFrameworkMoniker) ?? string.Empty;
FrameworkName = item.GetMetadata(MetadataKeys.FrameworkName) ?? string.Empty;
FrameworkVersion = item.GetMetadata(MetadataKeys.FrameworkVersion) ?? string.Empty;
}
private TargetMetadata(
DependencyType type,
IList<string> dependencies,
bool isTopLevelDependency,
string runtimeIdentifier,
string targetFrameworkMoniker,
string frameworkName,
string frameworkVersion)
: base(type, dependencies, isTopLevelDependency)
{
RuntimeIdentifier = runtimeIdentifier;
TargetFrameworkMoniker = targetFrameworkMoniker;
FrameworkName = frameworkName;
FrameworkVersion = frameworkVersion;
}
public string RuntimeIdentifier { get; }
public string TargetFrameworkMoniker { get; }
public string FrameworkName { get; }
public string FrameworkVersion { get; }
public override IDictionary<string, string> ToDictionary()
{
return new Dictionary<string, string>
{
{ MetadataKeys.RuntimeIdentifier, RuntimeIdentifier },
{ MetadataKeys.TargetFrameworkMoniker, TargetFrameworkMoniker },
{ MetadataKeys.FrameworkName, FrameworkName },
{ MetadataKeys.FrameworkVersion, FrameworkVersion },
{ MetadataKeys.Type, Type.ToString() },
{ DependenciesMetadata, string.Join(";", Dependencies) }
};
}
public override ItemMetadata Clone()
{
return new TargetMetadata(
Type,
Dependencies,
IsTopLevelDependency,
RuntimeIdentifier,
TargetFrameworkMoniker,
FrameworkName,
FrameworkVersion);
}
}
private class PackageMetadata : ItemMetadata
{
public PackageMetadata(ITaskItem item)
: base(DependencyType.Package)
{
Name = item.GetMetadata(MetadataKeys.Name) ?? string.Empty;
Version = item.GetMetadata(MetadataKeys.Version) ?? string.Empty;
Resolved = Type != DependencyType.Unknown && !string.IsNullOrEmpty(item.GetMetadata(MetadataKeys.ResolvedPath));
Path = (Resolved
? item.GetMetadata(MetadataKeys.ResolvedPath)
: item.GetMetadata(MetadataKeys.Path)) ?? string.Empty;
}
protected PackageMetadata(
DependencyType type,
IList<string> dependencies,
bool isTopLevelDependency,
string name,
string version,
string path,
bool resolved,
bool isImplicitlyDefined)
: base(type, dependencies, isTopLevelDependency)
{
Name = name;
Version = version;
Path = path;
Resolved = resolved;
IsImplicitlyDefined = isImplicitlyDefined;
}
public string Name { get; protected set; }
public string Version { get; }
public string Path { get; }
public bool Resolved { get; }
public bool IsImplicitlyDefined { get; set; }
public override IDictionary<string, string> ToDictionary()
{
return new Dictionary<string, string>
{
{ MetadataKeys.Name, Name },
{ MetadataKeys.Version, Version },
{ MetadataKeys.Path, Path },
{ MetadataKeys.Type, Type.ToString() },
{ MetadataKeys.IsImplicitlyDefined, IsImplicitlyDefined.ToString() },
{ MetadataKeys.IsTopLevelDependency, IsTopLevelDependency.ToString() },
{ ResolvedMetadata, Resolved.ToString() },
{ DependenciesMetadata, string.Join(";", Dependencies) }
};
}
public override ItemMetadata Clone()
{
return new PackageMetadata(
Type,
Dependencies,
IsTopLevelDependency,
Name,
Version,
Path,
Resolved,
IsImplicitlyDefined);
}
}
private class AssemblyMetadata : PackageMetadata
{
public AssemblyMetadata(DependencyType type,
ITaskItem item,
string name)
: base(item)
{
Name = name ?? string.Empty;
Type = type;
}
}
/// <summary>
/// Represents metadata for a Reference item that we want to pretend was resolved as a
/// standard NuGet package assembly.
/// </summary>
private class ExistingReferenceItemMetadata : ItemMetadata
{
public ExistingReferenceItemMetadata(string name, string path, bool visible)
: base(
type: DependencyType.Assembly,
dependencies: null,
isTopLevelDependency: false)
{
Name = name;
Path = path;
Visible = visible;
}
public string Name { get; }
public string Path { get; }
public bool Visible { get; }
public override IDictionary<string, string> ToDictionary()
{
return new Dictionary<string, string>
{
{ MetadataKeys.Name, Name },
{ MetadataKeys.Path, Path },
{ MetadataKeys.Type, Type.ToString() },
{ MetadataKeys.IsImplicitlyDefined, "false" },
{ MetadataKeys.IsTopLevelDependency, "false" },
{ ResolvedMetadata, "true" },
{ VisibleMetadata, Visible.ToString() },
{ DependenciesMetadata, string.Empty }
};
}
public override ItemMetadata Clone()
{
return new ExistingReferenceItemMetadata(
Name,
Path,
Visible);
}
}
private sealed class DiagnosticMetadata : ItemMetadata
{
public DiagnosticMetadata(ITaskItem item)
: base(DependencyType.Diagnostic)
{
DiagnosticCode = item.GetMetadata(MetadataKeys.DiagnosticCode) ?? string.Empty;
Message = item.GetMetadata(MetadataKeys.Message) ?? string.Empty;
FilePath = item.GetMetadata(MetadataKeys.FilePath) ?? string.Empty;
Severity = item.GetMetadata(MetadataKeys.Severity) ?? string.Empty;
StartLine = item.GetMetadata(MetadataKeys.StartLine) ?? string.Empty;
StartColumn = item.GetMetadata(MetadataKeys.StartColumn) ?? string.Empty;
EndLine = item.GetMetadata(MetadataKeys.EndLine) ?? string.Empty;
EndColumn = item.GetMetadata(MetadataKeys.EndColumn) ?? string.Empty;
}
private DiagnosticMetadata(
DependencyType type,
IList<string> dependencies,
bool isTopLevelDependency,
string diagnosticCode,
string message,
string filePath,
string severity,
string startLine,
string startColumn,
string endLine,
string endColumn)
: base(type, dependencies, isTopLevelDependency)
{
DiagnosticCode = diagnosticCode;
Message = message;
FilePath = filePath;
Severity = severity;
StartLine = startLine;
StartColumn = startColumn;
EndLine = endLine;
EndColumn = endColumn;
}
public string DiagnosticCode { get; }
public string Message { get; }
public string FilePath { get; }
public string Severity { get; }
public string StartLine { get; }
public string StartColumn { get; }
public string EndLine { get; }
public string EndColumn { get; }
public override IDictionary<string, string> ToDictionary()
{
return new Dictionary<string, string>
{
{ MetadataKeys.Name, Message },
{ MetadataKeys.DiagnosticCode, DiagnosticCode },
{ MetadataKeys.Message, Message },
{ MetadataKeys.FilePath, FilePath },
{ MetadataKeys.Severity, Severity },
{ MetadataKeys.StartLine, StartLine },
{ MetadataKeys.StartColumn, StartColumn },
{ MetadataKeys.EndLine, EndLine },
{ MetadataKeys.EndColumn, EndColumn },
{ MetadataKeys.Type, Type.ToString() },
{ DependenciesMetadata, string.Join(";", Dependencies) }
};
}
public override ItemMetadata Clone()
{
return new DiagnosticMetadata(
Type,
Dependencies,
IsTopLevelDependency,
DiagnosticCode,
Message,
FilePath,
Severity,
StartLine,
StartColumn,
EndLine,
EndColumn);
}
}
/// <summary>
/// Represents the FileDependency metadata for a Reference item that we want to pretend was
/// resolved as a standard NuGet package assembly.
/// </summary>
private sealed class ExistingReferenceItemDependency : ITaskItem
{
private readonly Dictionary<string, string> _metadata = new Dictionary<string, string>(capacity: 3, comparer: StringComparer.OrdinalIgnoreCase);
public ExistingReferenceItemDependency(string itemSpec, string parentTarget, string parentPackage)
{
ItemSpec = itemSpec;
_metadata[MetadataKeys.FileGroup] = CompileTimeAssemblyMetadata;
_metadata[MetadataKeys.ParentTarget] = parentTarget;
_metadata[MetadataKeys.ParentPackage] = parentPackage;
}
public string ItemSpec { get; set; }
public ICollection MetadataNames => _metadata.Keys;
public int MetadataCount => _metadata.Count;
public IDictionary CloneCustomMetadata()
{
return new Dictionary<string, string>(_metadata, _metadata.Comparer);
}
public void CopyMetadataTo(ITaskItem destinationItem)
{
foreach (var pair in _metadata)
{
destinationItem.SetMetadata(pair.Key, pair.Value);
}
}
public string GetMetadata(string metadataName)
{
if (_metadata.TryGetValue(metadataName, out string metadataValue))
{
return metadataValue;
}
return null;
}
public void RemoveMetadata(string metadataName)
{
_metadata.Remove(metadataName);
}
public void SetMetadata(string metadataName, string metadataValue)
{
_metadata[metadataName] = metadataValue;
}
}
internal static HashSet<string> GetImplicitPackageReferences(string defaultImplicitPackages)
{
var implicitPackageReferences = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
if (string.IsNullOrEmpty(defaultImplicitPackages))
{
return implicitPackageReferences;
}
var packageNames = defaultImplicitPackages.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (packageNames == null || packageNames.Length <= 0)
{
return implicitPackageReferences;
}
foreach (var packageReference in packageNames)
{
implicitPackageReferences.Add(packageReference);
}
return implicitPackageReferences;
}
}
}