Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/SourceBuild/content/eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
<!-- msbuild dependencies -->
<MicrosoftBuildVersion>17.12.6</MicrosoftBuildVersion>
<!-- nuget dependencies -->
<NuGetProtocolVersion>6.12.1</NuGetProtocolVersion>
<NuGetProjectModelVersion>6.12.1</NuGetProjectModelVersion>
<NuGetProtocolVersion>6.13.1</NuGetProtocolVersion>
<NuGetProjectModelVersion>6.13.1</NuGetProjectModelVersion>
<!-- runtime dependencies -->
<MicrosoftExtensionsFileSystemGlobbingVersion>9.0.0</MicrosoftExtensionsFileSystemGlobbingVersion>
<MicrosoftExtensionsLoggingConsoleVersion>9.0.0</MicrosoftExtensionsLoggingConsoleVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Xml.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.LibraryModel;
using NuGet.ProjectModel;

namespace Microsoft.DotNet.UnifiedBuild.Tasks;
Expand Down Expand Up @@ -48,8 +49,9 @@ public override bool Execute()
{
Log.LogMessage($"Scanning for SBRP Package Usage...");

ReadSbrpPackages("referencePackages", trackTfms: true);
ReadSbrpPackages("textOnlyPackages", trackTfms: false);
ReadSbrpPackages(Path.Combine("referencePackages", "src"), trackTfms: true);
ReadSbrpPackages(Path.Combine("targetPacks", "ILsrc"), trackTfms: false);
ReadSbrpPackages(Path.Combine("textOnlyPackages", "src"), trackTfms: false);

ScanProjectReferences();

Expand Down Expand Up @@ -110,11 +112,10 @@ private void PurgeNonReferencedReferences()
private IEnumerable<PackageInfo> GetUnreferencedSbrps() =>
_sbrpPackages.Values.Where(pkg => pkg.References.Count == 0);

private string GetSbrpPackagesPath(string packageType) => Path.Combine(SbrpRepoSrcPath, packageType, "src");

private void ReadSbrpPackages(string packageType, bool trackTfms)
private void ReadSbrpPackages(string packageSrcRelativePath, bool trackTfms)
{
foreach (string projectPath in Directory.GetFiles(GetSbrpPackagesPath(packageType), "*.csproj", SearchOption.AllDirectories))
string packageSrcPath = Path.Combine(SbrpRepoSrcPath, packageSrcRelativePath);
foreach (string projectPath in Directory.GetFiles(packageSrcPath, "*.csproj", SearchOption.AllDirectories))
{
DirectoryInfo? directory = Directory.GetParent(projectPath);
string version = directory!.Name;
Expand Down Expand Up @@ -163,28 +164,40 @@ private void ScanProjectReferences()
LockFile lockFile = new LockFileFormat().Read(projectJsonFile);
foreach (LockFileTargetLibrary lib in lockFile.Targets.SelectMany(t => t.Libraries))
{
if (!_sbrpPackages.TryGetValue(PackageInfo.GetId(lib.Name, lib.Version?.ToString()), out PackageInfo? info))
{
continue;
}

if (!info.References.TryGetValue(lockFile.Path, out HashSet<string>? referencedTfms))
{
referencedTfms = [];
info.References.Add(lockFile.Path, referencedTfms);
}

IEnumerable<string> tfms = lib.CompileTimeAssemblies
.Where(asm => asm.Path.StartsWith("lib") || asm.Path.StartsWith("ref"))
.Select(asm => asm.Path.Split('/')[1]);
foreach (string tfm in tfms)
{
referencedTfms.Add(tfm);
}

TrackPackageReference(lockFile.Path, lib.Name, lib.Version?.ToString(), tfms);
}

foreach (DownloadDependency downloadDep in lockFile.PackageSpec.TargetFrameworks.SelectMany(fx => fx.DownloadDependencies))
{
TrackPackageReference(lockFile.Path, downloadDep.Name, downloadDep.VersionRange.MinVersion?.ToString(), Enumerable.Empty<string>());
}
}
}

private void TrackPackageReference(string lockFilePath, string? name, string? version, IEnumerable<string> tfms)
{
string id = PackageInfo.GetId(name, version);
if (!_sbrpPackages.TryGetValue(id, out PackageInfo? info))
{
return;
}

if (!info.References.TryGetValue(lockFilePath, out HashSet<string>? referencedTfms))
{
referencedTfms = [];
info.References.Add(lockFilePath, referencedTfms);
}

foreach (string tfm in tfms)
{
referencedTfms!.Add(tfm);
}
}

private record PackageInfo(string Name, string Version, string Path, HashSet<string>? Tfms = default)
{
public string Id => GetId(Name, Version);
Expand Down