Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 19, 2025

This PR implements a new slnx command that creates or updates Visual Studio solution files (.slnx) with automatic project discovery and intelligent type-based organization. The command supports scanning multiple root directories to create unified solution files across complex repository structures and automatically identifies obsolete projects based on Git commit history.

Features

The slnx command automatically:

  • Discovers all .NET project files (.csproj, .fsproj, .vbproj) recursively in specified directories
  • Analyzes project properties to determine their type and purpose
  • Organizes projects into logical folders by type (Web, Console, Libraries, Tests, etc.)
  • Creates properly formatted .slnx files compatible with Visual Studio
  • Supports multiple root directories for comprehensive project discovery
  • Detects obsolete projects based on Git commit history and organizes them separately

Project Type Detection

The command intelligently categorizes projects based on their SDK, OutputType, and other properties:

  • Web - ASP.NET Core applications (Microsoft.NET.Sdk.Web)
  • Console - Console applications (OutputType: Exe)
  • Libraries - Class libraries (default for SDK-style projects)
  • NuGet Packages - Packable libraries (IsPackable: true)
  • Tests - Test projects (naming patterns or IsTestProject: true)
  • WPF Applications - WPF projects (UseWPF: true)
  • WinForms Applications - Windows Forms projects (UseWindowsForms: true)
  • Blazor Applications - Blazor web projects
  • Worker Services - Background services (Microsoft.NET.Sdk.Worker)
  • Azure Functions - Function apps

Git-Based Obsolete Project Detection

Projects in Git repositories are analyzed for their last commit activity. Projects older than the configurable threshold are automatically moved to an "Obsolete" group with time-based sub-folders:

  • 6-12 Months - Recently obsolete projects
  • 1-2 Years - Moderately old projects
  • 2-3 Years - Old projects
  • 3+ Years - Very old projects

Usage Examples

# Create solution file for current directory
bld slnx

# Create solution with custom name
bld slnx --output MySolution.slnx

# Scan multiple directories
bld slnx src tests tools

# Multiple directories with custom output
bld slnx src tests --output MyProject.slnx

# Custom obsolete threshold (12 months instead of default 6)
bld slnx --obsolete-threshold 12

# Scan specific directory with verbose output
bld slnx /path/to/projects --verbosity Verbose

Multiple Root Directory Support

The command now accepts multiple root directory arguments, allowing you to:

  • Scan multiple project directories in a single command
  • Create unified solution files across complex repository structures
  • Automatically handle duplicate projects if root paths overlap
  • Validate all specified directories exist before processing

Robust Implementation

The command includes:

  • Fallback parsing when MSBuild evaluation fails (common in CI environments)
  • Regex-based property extraction from project XML for reliability
  • Comprehensive error handling with informative messages
  • Configurable recursion depth for large repositories
  • Update-in-place capability for existing solution files
  • Path validation for all specified root directories
  • Duplicate project detection across overlapping paths
  • Git integration for commit history analysis and obsolete project detection

Generated Output

<Solution>
  <Configurations>
    <Platform Name="Any CPU" />
    <Platform Name="x64" />
    <Platform Name="x86" />
  </Configurations>
  <Folder Name="/Web/">
    <Project Path="src/WebApp/WebApp.csproj" />
  </Folder>
  <Folder Name="/Libraries/">
    <Project Path="src/Core/Core.csproj" />
  </Folder>
  <Folder Name="/Tests/">
    <Project Path="tests/Core.Tests/Core.Tests.csproj" />
  </Folder>
  <Folder Name="/Obsolete/1-2 Years/">
    <Project Path="legacy/OldProject/OldProject.csproj" />
  </Folder>
</Solution>

This addresses the need for automated solution file management in .NET projects, especially useful for repositories with many projects across multiple directories that need logical organization. The Git-based obsolete detection helps maintain clean solution files by automatically identifying and segregating projects that haven't been actively maintained.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Add a new cmd slnx which - creates a new slnx file or updates an existing slnx file in the current directory - Adds all project files it findes below the root directory to the file - Groups the projects by type. Creates folder per type and adds the aff... Add slnx command to create organized Visual Studio solution files Sep 19, 2025
@Copilot Copilot AI requested a review from dlosch September 19, 2025 18:55
Copilot finished work on behalf of dlosch September 19, 2025 18:55
@dlosch
Copy link
Owner

dlosch commented Sep 19, 2025

@copilot I am so disappointed with you.

The project file could not be loaded. Microsoft.VisualStudio.SolutionPersistence.Model.SolutionException: Solution folder path 'Console' must start and end with '/'. (Parameter 'path')
---> Microsoft.VisualStudio.SolutionPersistence.Model.SolutionArgumentException: Solution folder path 'Console' must start and end with '/'. (Parameter 'path')
at Microsoft.VisualStudio.SolutionPersistence.Model.SolutionModel.AddFolder(String path)
at Microsoft.VisualStudio.SolutionPersistence.Serializer.Xml.XmlDecorators.XmlFolder.AddToModel(SolutionModel solutionModel, List1 newProjects) --- End of inner exception stack trace --- at Microsoft.VisualStudio.SolutionPersistence.Serializer.Xml.XmlDecorators.XmlFolder.AddToModel(SolutionModel solutionModel, List1 newProjects)
at Microsoft.VisualStudio.SolutionPersistence.Serializer.Xml.XmlDecorators.XmlSolution.ToModel()
at Microsoft.VisualStudio.SolutionPersistence.Serializer.Xml.XmlDecorators.SlnxFile.ToModel()
at Microsoft.VisualStudio.SolutionPersistence.Serializer.Xml.SlnXmlSerializer.Reader.Parse()
at Microsoft.VisualStudio.SolutionPersistence.Serializer.Xml.SlnXmlSerializer.ReadModelAsync(String fullPath, Stream reader, CancellationToken cancellationToken)
at Microsoft.VisualStudio.SolutionPersistence.Serializer.SingleFileSerializerBase`1.Microsoft.VisualStudio.SolutionPersistence.ISolutionSerializer.OpenAsync(String moniker, CancellationToken ca
ncellationToken)
at Microsoft.Build.Construction.SolutionFile.ParseUsingNewParser()

Build failed with 1 error(s) in 0.0s

Copy link
Author

Copilot AI commented Sep 19, 2025

@copilot I am so disappointed with you.

The project file could not be loaded. Microsoft.VisualStudio.SolutionPersistence.Model.SolutionException: Solution folder path 'Console' must start and end...

Fixed the folder path format issue. The .slnx format requires folder paths to start and end with '/' characters. Updated the XML generation to use "/Console/" instead of "Console" for folder names. This resolves the Visual Studio SolutionPersistence.Model error you encountered. Commit 9b7bcd4.

Copilot finished work on behalf of dlosch September 19, 2025 19:50
@dlosch
Copy link
Owner

dlosch commented Sep 19, 2025

@copilot it should be possible to specify multiple root folders and the command should traverse all the folders below all of these root folders for project files and add all of these projects to the new slnx.

Copy link
Author

Copilot AI commented Sep 19, 2025

@copilot it should be possible to specify multiple root folders and the command should traverse all the folders below all of these root folders for project files and add all of these projects to the ...

Added support for multiple root directories. The slnx command now accepts multiple directory arguments and will scan all specified directories for projects, combining them into a single organized solution file.

Usage examples:

  • bld slnx src tests tools - scan multiple directories
  • bld slnx dir1 dir2 --output MySolution.slnx - with custom output name

The command validates all directories exist, removes duplicates if paths overlap, and generates correct relative paths from the current working directory. Commit 3114700.

@Copilot Copilot AI changed the title Add slnx command to create organized Visual Studio solution files Add slnx command to create organized Visual Studio solution files with multiple root directory support Sep 19, 2025
@dlosch
Copy link
Owner

dlosch commented Sep 19, 2025

@copilot additional group projects by git commit status. If the project is inside a git repo, for the folder where the project file resides and all nested folders, check when the last commit was made to the repo. If it is longer than a configurable duration with a default of 6 months, move the folder to a Obsolete group in the slnx and move the projects in buckets aka subfolders grouped by how old the last commit is

Copy link
Author

Copilot AI commented Sep 19, 2025

@copilot additional group projects by git commit status. If the project is inside a git repo, for the folder where the project file resides and all nested folders, check when the last commit was made...

Added Git commit status-based project categorization. Projects in Git repositories are analyzed for their last commit date. Projects older than the configurable threshold (default 6 months) are moved to an "Obsolete" group with time-based sub-folders:

  • "6-12 Months"
  • "1-2 Years"
  • "2-3 Years"
  • "3+ Years"

Usage:

  • bld slnx - uses default 6-month threshold
  • bld slnx --obsolete-threshold 12 - custom 12-month threshold

The command detects Git repositories, checks last commit dates for project directories, and organizes obsolete projects separately from active ones. Commit 3bfb4c5.

@Copilot Copilot AI changed the title Add slnx command to create organized Visual Studio solution files with multiple root directory support Add slnx command to create organized Visual Studio solution files with multiple root directory support and Git-based obsolete project detection Sep 19, 2025
Copilot finished work on behalf of dlosch September 19, 2025 20: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