Skip to content

Add create-solution-filters command for converting multiple solutions#171

Open
psmulovics wants to merge 6 commits intomainfrom
psmulovics/issue-49-add-command-for-converting-multiple-solu-6dd346
Open

Add create-solution-filters command for converting multiple solutions#171
psmulovics wants to merge 6 commits intomainfrom
psmulovics/issue-49-add-command-for-converting-multiple-solu-6dd346

Conversation

@psmulovics
Copy link
Copy Markdown
Member

Overview

Implements Issue #49 to add a new command that converts multiple .sln files in a multi-solution repository into a single consolidated solution with individual .slnf (solution filter) files for each original solution.

This enables teams to migrate from a multi-solution structure to a monorepo while maintaining separate filtering options for different solution contexts.

Command Syntax

please create-solution-filters --from <glob-pattern> --target <target-solution>

Behavior

The command performs the following steps:

  1. Discovery: Finds all .sln files matching the glob pattern
  2. Consolidation:
    • Creates or uses existing target solution
    • Extracts projects from each source solution
    • Adds them to the target under solution folders (named after source solutions)
  3. Filter Generation: Creates .slnf JSON files for each original solution that filter the target solution to show only its original projects
  4. Cleanup: Deletes source .sln files after successful conversion

Example

Before:

Solution1.sln (contains ProjectA, ProjectB)
Solution2.sln (contains ProjectC, ProjectD)

After running: please create-solution-filters --from "Solution*.sln" --target "Consolidated.sln"

Result:

Consolidated.sln (contains all projects organized by solution folder)
├── Solution1/
│   ├── ProjectA
│   └── ProjectB
├── Solution2/
│   ├── ProjectC
│   └── ProjectD

Solution1.slnf (filters to Solution1's projects)
Solution2.slnf (filters to Solution2's projects)

Solution1.sln (deleted)
Solution2.sln (deleted)

Implementation Details

  • Architecture: Follows existing dotnet-please patterns (attribute-based command discovery, Mediator pattern)
  • Glob Support: Reuses existing MSBuildHelper.GetProjectInfosFromGlob() for flexible pattern matching
  • CLI Integration: Uses DotNetCliHelper.AddProjectToSolution() for reliable project addition via dotnet sln CLI
  • Solution Filters: Generates valid JSON .slnf files with proper camelCase property names
  • Dry-Run Support: Full integration with existing --dry-run flag
  • Error Handling: Validates inputs (no matching solutions, invalid paths) and reports errors gracefully

Testing

Added comprehensive unit tests covering:

  • Two-solution consolidation (dry-run and live modes)
  • Reuse of existing target solution
  • Multiple projects per solution
  • Single solution handling
  • All tests use [Theory, CombinatorialData] for dry-run variations

Result: ✅ All 8 tests pass

Files Changed

  • DotNetPlease/Commands/CreateSolutionFilters.cs (255 lines): Command implementation
  • DotNetPlease.Tests/Commands/CreateSolutionFiltersTests.cs (240 lines): Unit tests

Notes

  • Command is fully integrated and discoverable via please --help
  • No breaking changes to existing functionality
  • Leverages only existing helpers and standard .NET libraries (System.Text.Json)

@psmulovics psmulovics requested a review from a team as a code owner March 31, 2026 19:46
@psmulovics psmulovics force-pushed the psmulovics/issue-49-add-command-for-converting-multiple-solu-6dd346 branch from 564b0b9 to 9f456f6 Compare April 1, 2026 17:39
… to monorepo with filters

Implements issue #49 to add a new command that converts multiple .sln files
into a single consolidated solution with individual .slnf solution filter files.

Command syntax:
  please create-solution-filters --from <glob-pattern> --target <target-solution>

Behavior:
- Creates or uses existing target solution
- Adds all projects from source solutions under solution folders
- Generates .slnf files for each original solution as filters
- Deletes source solution files after consolidation
- Supports --dry-run flag

Includes comprehensive unit tests covering:
- Two solution consolidation
- Multiple projects per solution
- Single solution handling
- Existing target solution reuse

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@psmulovics psmulovics force-pushed the psmulovics/issue-49-add-command-for-converting-multiple-solu-6dd346 branch from 9f456f6 to 96d1998 Compare April 1, 2026 17:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new please create-solution-filters command to help migrate multi-solution repositories into a single consolidated solution while generating per-solution .slnf filter files.

Changes:

  • Introduces create-solution-filters command to discover source solutions, consolidate projects into a target solution, generate .slnf files, and delete original .sln files.
  • Adds unit tests covering consolidation scenarios (2 solutions, existing target, multiple projects, single solution) with dry-run permutations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
DotNetPlease/Commands/CreateSolutionFilters.cs Implements the new CLI command for consolidating solutions and producing solution filter files.
DotNetPlease.Tests/Commands/CreateSolutionFiltersTests.cs Adds test coverage for the new command, including dry-run behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread DotNetPlease/Commands/CreateSolutionFilters.cs Outdated
Comment thread DotNetPlease/Commands/CreateSolutionFilters.cs
Comment thread DotNetPlease/Commands/CreateSolutionFilters.cs
Comment thread DotNetPlease/Commands/CreateSolutionFilters.cs
Comment thread DotNetPlease/Commands/CreateSolutionFilters.cs
Comment thread DotNetPlease.Tests/Commands/CreateSolutionFiltersTests.cs Outdated
Comment thread DotNetPlease/Commands/CreateSolutionFilters.cs
Copy link
Copy Markdown
Member

@ZKRobi ZKRobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all the copilot review seems to be pretty on point with this PR.

Comment thread DotNetPlease/Commands/CreateSolutionFilters.cs
Comment thread DotNetPlease/Commands/CreateSolutionFilters.cs
Comment thread DotNetPlease/Commands/CreateSolutionFilters.cs
psmulovics and others added 4 commits April 7, 2026 13:09
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Fixes for unresolved review comments:
- Validate target is a .sln file early with clear error message (line 63)
- Prevent accidental deletion of target solution during cleanup (line 230)
- Add project deduplication to handle shared projects across solutions (line 165)
- Fix .slnf JSON schema to use correct 'solution' object with 'path' and 'projects' properties (line 202)
- Compute relative paths from .slnf file location instead of target solution directory

Merged suggestions already applied:
- DiscoverSourceSolutions uses direct file globbing instead of project enumeration
- ExtractProjectsFromSources throws immediately on parsing failure for all-or-nothing behavior

Test updates:
- VerifyFilterFile validates correct .slnf schema with path and projects arrays
- All 8 unit tests passing (with dry-run variations)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@psmulovics psmulovics requested a review from ZKRobi April 22, 2026 20:33
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.

4 participants