Skip to content

Commit 68c629b

Browse files
Misc updates to the WriteSbrpUsageReport task (dotnet#42405)
1 parent 36e9334 commit 68c629b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.UnifiedBuild.Tasks/WriteSbrpUsageReport.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private void GenerateUsageReport()
6262
{
6363
PackageInfo[] existingSbrps = [.. _sbrpPackages.Values.OrderBy(pkg => pkg.Id)];
6464
PurgeNonReferencedReferences();
65-
IEnumerable<string> unreferencedSbrps = GetUnreferencedSbrps().Select(pkg => pkg.Id).OrderBy(id => id);
65+
IEnumerable<string> unreferencedSbrps = GetUnreferencedSbrps().Select(pkg => pkg.Path).OrderBy(id => id);
6666
Report report = new(existingSbrps, unreferencedSbrps);
6767

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

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

180180
// Dictionary of projects referencing the SBRP and the TFMs referenced by each project
181181
public Dictionary<string, HashSet<string>> References { get; } = [];
182+
183+
public static string GetId(string? Name, string? Version) => $"{Name?.ToLowerInvariant()}/{Version}";
182184
}
183185

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

0 commit comments

Comments
 (0)