Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 17, 2025

Overview

This PR extracts a reusable NuGetManager base class from NuGetDiff, enabling package management functionality to be used independently without requiring API diffing capabilities.

Changes

New NuGetManager Base Class

Created a new base class containing core NuGet package management functionality:

  • OpenPackageAsync - Opens and downloads NuGet packages from remote sources
  • ExtractPackageToDirectoryAsync - Extracts packages to a specified directory
  • ExtractCachedPackageAsync - Extracts packages to a cache directory with deduplication
  • GetCachedPackagePath - Returns the file path for cached packages
  • GetCachedPackageDirectory - Returns the directory path for cached packages

Dependency Resolution

Added new overloads with an includeDependencies parameter to extraction methods:

await manager.ExtractPackageToDirectoryAsync("MyPackage", "1.0.0", "./output", includeDependencies: true);
await manager.ExtractCachedPackageAsync("MyPackage", "1.0.0", includeDependencies: true);

When includeDependencies is true, the manager recursively downloads and extracts all package dependencies, making it easier to prepare complete package environments.

Refactored NuGetDiff

  • Now inherits from NuGetManager
  • Removed 194 lines of duplicate code
  • All existing public APIs preserved for backward compatibility
  • Protected access to NuGet source, cache, and logger for derived classes

Usage Examples

The new base class can be used independently:

// Simple package management
var manager = new NuGetManager();
using var reader = await manager.OpenPackageAsync("Newtonsoft.Json", "13.0.1");

// Extract with dependencies
await manager.ExtractPackageToDirectoryAsync("MyPackage", "1.0.0", "./packages", includeDependencies: true);

// Use custom cache location
manager.PackageCache = "./my-cache";
var cacheDir = await manager.ExtractCachedPackageAsync("SomePackage", "2.0.0");

And NuGetDiff retains all functionality:

var diff = new NuGetDiff();
// Package management capabilities
await diff.ExtractCachedPackageAsync("Package", "1.0.0", includeDependencies: true);
// API diff capabilities  
var result = await diff.GenerateAsync("Package", "1.0.0", "2.0.0");

Testing

  • Added 5 new tests covering NuGetManager functionality
  • All existing tests pass (78 passed, 11 expected failures due to missing Xamarin dependencies)
  • ABI compatibility verified - no breaking changes to public APIs

Benefits

  • Reusability: Package management can now be used without API diffing
  • Maintainability: Reduced code duplication by 194 lines
  • Extensibility: Dependency resolution available to base and derived classes
  • Separation of concerns: Package management logic isolated from API comparison logic

Fixes the feature request to extract reusable NuGet management functionality into a base class.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • aka.ms
    • Triggering command: dotnet build Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff.csproj (dns block)
    • Triggering command: dotnet test Mono.ApiTools.NuGetDiff.Tests/Mono.ApiTools.NuGetDiff.Tests.csproj --logger console;verbosity=minimal (dns block)
  • www.nuget.org
    • Triggering command: /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff.Tests/bin/Debug/net8.0/Mono.ApiTools.NuGetDiff.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff.Tests/bin/Debug/net8.0/Mono.ApiTools.NuGetDiff.Tests.deps.json /home/REDACTED/work/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff.Tests/bin/Debug/net8.0/testhost.dll --port 46645 --endpoint 127.0.0.1:046645 --role client --parentprocessid 3879 --telemetryoptedin false (dns block)
    • Triggering command: /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff.Tests/bin/Debug/net8.0/Mono.ApiTools.NuGetDiff.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff.Tests/bin/Debug/net8.0/Mono.ApiTools.NuGetDiff.Tests.deps.json /home/REDACTED/work/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff.Tests/bin/Debug/net8.0/testhost.dll --port 33309 --endpoint 127.0.0.1:033309 --role client --parentprocessid 4344 --telemetryoptedin false (dns block)
    • Triggering command: /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff.Tests/bin/Debug/net8.0/Mono.ApiTools.NuGetDiff.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff.Tests/bin/Debug/net8.0/Mono.ApiTools.NuGetDiff.Tests.deps.json /home/REDACTED/work/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff/Mono.ApiTools.NuGetDiff.Tests/bin/Debug/net8.0/testhost.dll --port 46211 --endpoint 127.0.0.1:046211 --role client --parentprocessid 4676 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Can you extract a base class for NuGetDiff that is a NuGetManager.

This manager should be able to:

  • open packages (OpenPackageAsync)
  • download/extract nugets (ExtractPackageToDirectoryAsync)
  • cache packages in the cache location (ExtractCachedPakcageAsync)
  • get directories (GetCachedPackagePath,GetCachedPackageDirectory)

Move any things this depends on into the new base as well.

Do not change the existing ABI.

Add new overloads for the extract methods that tak an extra bool includeDependencies parameter just before the cancellation token. This should be used to recursively download dependencies.

The goal is to move the members into a reusable base type that just downloads and manages nugets. This new typ should inherit and extend with the current nuget diff capabilities


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Oct 17, 2025
Copilot AI changed the title [WIP] Extract base NuGetManager class from NuGetDiff Extract NuGetManager base class with dependency resolution support Oct 18, 2025
Copilot AI requested a review from mattleibow October 18, 2025 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants