Skip to content

Commit

Permalink
Warn if retrieving the NuGetPackageId does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Mar 12, 2024
1 parent b329b90 commit 3a03786
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Chisel/ChiselTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public override bool Execute()
{
try
{
var resolvedPackages = new HashSet<string>(RuntimeAssemblies.Select(e => e.GetMetadata("NuGetPackageId")).Concat(NativeLibraries.Select(e => e.GetMetadata("NuGetPackageId"))));
var resolvedPackages = new HashSet<string>(RuntimeAssemblies.Select(NuGetPackageId).Concat(NativeLibraries.Select(NuGetPackageId)));
var graph = new DependencyGraph(resolvedPackages, ProjectAssetsFile, TargetFramework, RuntimeIdentifier, ChiselIgnores.Select(e => e.ItemSpec));
var (removed, notFound, removedRoots) = graph.Remove(ChiselPackages.Select(e => e.ItemSpec));

Expand All @@ -110,8 +110,8 @@ public override bool Execute()
Log.LogWarning($"The package {packageName} (defined in ChiselPackages) can't be removed from the dependency graph because it's a root");
}

RemoveRuntimeAssemblies = RuntimeAssemblies.Where(item => removed.Contains(item.GetMetadata("NuGetPackageId"))).ToArray();
RemoveNativeLibraries = NativeLibraries.Where(item => removed.Contains(item.GetMetadata("NuGetPackageId"))).ToArray();
RemoveRuntimeAssemblies = RuntimeAssemblies.Where(item => removed.Contains(NuGetPackageId(item))).ToArray();
RemoveNativeLibraries = NativeLibraries.Where(item => removed.Contains(NuGetPackageId(item))).ToArray();

if (string.IsNullOrEmpty(Graph) || Graph.Equals("false", StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -163,4 +163,15 @@ public override bool Execute()
return false;
}
}

private string NuGetPackageId(ITaskItem item)
{
var packageId = item.GetMetadata("NuGetPackageId");
if (string.IsNullOrEmpty(packageId))
{
var metadataNames = string.Join(", ", item.MetadataNames.OfType<string>().Select(e => $"\"{e}\""));
Log.LogWarning($"\"{item.ItemSpec}\" should contain \"NuGetPackageId\" metadata but contains {metadataNames}");
}
return packageId;
}
}

0 comments on commit 3a03786

Please sign in to comment.