Skip to content

Conversation

Copy link

Copilot AI commented Sep 13, 2025

This PR introduces a new Enumerator class that provides a unified interface for enumerating both solution files and project files based on the requirements in issue #250648a5. The implementation extends beyond the existing SlnScanner functionality to support transparent enumeration of all MSBuild project types.

Key Features

Unified Enumeration Interface

The new Enumerator class provides two complementary methods for enumeration:

  1. EnumerateProjectPaths() - Returns project file paths:

    • Solution files: .sln, .slnx, .slnf (extracts all projects from solutions)
    • Project files: .csproj, .vbproj, .sqlproj, .fsproj, .vcxproj (direct enumeration)
  2. EnumerateProjCfg() - Returns ProjCfg objects with configuration details:

    • Replicates SlnParser.ParseSolution logic for solution files
    • Enumerates projects in order and extracts configurations
    • Creates default configurations for standalone project files
    • Supports platform configurations for vcxproj files

Usage is controlled by the new EnumerationType enum:

var enumerator = new Enumerator(options, errorSink);

// Enumerate project paths from solution files
await foreach (var project in enumerator.EnumerateProjectPaths(path, EnumerationType.Sln)) {
    // Process each project found in solution files
}

// Enumerate project configurations with full configuration details
await foreach (var projCfg in enumerator.EnumerateProjCfg(path, EnumerationType.Sln)) {
    // Process ProjCfg with configuration and platform information
}

Performance Optimizations

  • Parallel Processing: Solution files are processed concurrently using Task.WhenAll for improved performance
  • Async Enumerable: Full async enumeration pattern for non-blocking operations
  • Efficient File Scanning: Leverages Directory.EnumerateFiles with optimized enumeration options

Enhanced Project Support

Extends beyond the current SlnScanner to support:

  • All solution formats: .sln, .slnx, .slnf
  • All MSBuild project types: .csproj, .vbproj, .sqlproj, .fsproj, .vcxproj
  • Recursive project enumeration from solution files
  • Direct project file discovery
  • Configuration extraction from solution files
  • Platform-specific configurations for native projects

Implementation Details

Core Components

  • Enumerator class in bld/Infrastructure/Enumerator.cs
  • EnumerationType enum added to bld/Models/DirectoryModels.cs
  • EnumeratorDemoService showcasing usage patterns
  • Comprehensive test suite in bld.Tests/EnumeratorTests.cs

Integration Points

The new Enumerator can be used as a drop-in replacement or complement to SlnScanner and SlnParser in existing services:

  • CleaningApplication
  • NugetAnalysisApplication
  • TfmService
  • OutdatedService
  • And other services using solution/project enumeration

Backward Compatibility

The implementation maintains full backward compatibility with existing code while providing enhanced functionality through the new enumeration interface.

Example Usage

// Traditional approach with SlnScanner + SlnParser
var scanner = new SlnScanner(options, errorSink);
await foreach (var sln in scanner.Enumerate(rootPath)) {
    await foreach (var projCfg in slnParser.ParseSolution(sln)) {
        // Process project configuration
    }
}

// New unified approach with Enumerator
var enumerator = new Enumerator(options, errorSink);
await foreach (var projCfg in enumerator.EnumerateProjCfg(rootPath, EnumerationType.Sln)) {
    // Process project configuration directly - no separate parsing needed
}

This implementation addresses all requirements from the issue: transparent enumeration of solution and project files, support for all specified file formats, recursive project enumeration, configuration extraction, and performance optimization through parallelization.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Based on the code in SlnScanner.Enumerate create a new Enumerator class which can enumerate sln, slnx, slnf (current logic in SlnScanner) as well as csproj, vbproj, sqlproj transarently From a base directory, it should take an enum (Sln, Project), th... Implement new Enumerator class for unified solution and project file enumeration Sep 13, 2025
Copilot AI requested a review from dlosch September 13, 2025 08:09
Copilot finished work on behalf of dlosch September 13, 2025 08:09
@dlosch
Copy link
Owner

dlosch commented Sep 13, 2025

@copilot can you add another enumerator method to Enumerator class which performs the same logic as EnumerateProjectPaths but a) returns ProjCfg (look at SlnParser.ParseSolution) . it also needs to perform the same logic as SlnParser (enumerating projects in order and extracr configurations_

Copy link
Author

Copilot AI commented Sep 13, 2025

@copilot can you add another enumerator method to Enumerator class which performs the same logic as EnumerateProjectPaths but a) returns ProjCfg (look at SlnParser.ParseSolution) . it also needs to p...

I've added the EnumerateProjCfg method to the Enumerator class as requested. This method performs the same logic as SlnParser.ParseSolution:

Key Features:

  • Returns IAsyncEnumerable<ProjCfg> instead of project paths
  • Enumerates projects in order and extracts configurations from solution files
  • Handles both solution files (with configuration extraction) and project files (with default configurations)
  • Supports platform configurations for vcxproj files
  • Includes optional createDefaultDebugConfiguration parameter like SlnParser

Usage:

await foreach (var projCfg in enumerator.EnumerateProjCfg(path, EnumerationType.Sln)) {
    // Process ProjCfg with configuration and platform information
}

The implementation replicates SlnParser's logic for project ordering and configuration extraction. All tests pass, including comprehensive coverage for solution files, vcxproj with platforms, and default configuration handling. (commit 668b7b9)

Copilot AI changed the title Implement new Enumerator class for unified solution and project file enumeration Implement new Enumerator class for unified solution and project file enumeration with ProjCfg support Sep 13, 2025
Copilot finished work on behalf of dlosch September 13, 2025 14:44
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