Skip to content

Commit

Permalink
Misc updates to the WriteSbrpUsageReport task (#42405)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSimons authored Jul 27, 2024
1 parent 36e9334 commit 68c629b
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void GenerateUsageReport()
{
PackageInfo[] existingSbrps = [.. _sbrpPackages.Values.OrderBy(pkg => pkg.Id)];
PurgeNonReferencedReferences();
IEnumerable<string> unreferencedSbrps = GetUnreferencedSbrps().Select(pkg => pkg.Id).OrderBy(id => id);
IEnumerable<string> unreferencedSbrps = GetUnreferencedSbrps().Select(pkg => pkg.Path).OrderBy(id => id);
Report report = new(existingSbrps, unreferencedSbrps);

string reportFilePath = Path.Combine(OutputPath, "sbrpPackageUsage.json");
Expand Down Expand Up @@ -151,7 +151,7 @@ private void ScanProjectReferences()
LockFile lockFile = new LockFileFormat().Read(projectJsonFile);
foreach (LockFileTargetLibrary lib in lockFile.Targets.SelectMany(t => t.Libraries))
{
if (!_sbrpPackages.TryGetValue($"{lib.Name}/{lib.Version}", out PackageInfo? info))
if (!_sbrpPackages.TryGetValue(PackageInfo.GetId(lib.Name, lib.Version?.ToString()), out PackageInfo? info))
{
continue;
}
Expand All @@ -175,10 +175,12 @@ private void ScanProjectReferences()

private record PackageInfo(string Name, string Version, string Path, HashSet<string>? Tfms = default)
{
public string Id => $"{Name}/{Version}";
public string Id => GetId(Name, Version);

// Dictionary of projects referencing the SBRP and the TFMs referenced by each project
public Dictionary<string, HashSet<string>> References { get; } = [];

public static string GetId(string? Name, string? Version) => $"{Name?.ToLowerInvariant()}/{Version}";
}

private record Report(IEnumerable<PackageInfo> Sbrps, IEnumerable<string> UnreferencedSbrps);
Expand Down

0 comments on commit 68c629b

Please sign in to comment.