readme.md 9.5 KB

Visual Studio 2022 Filtered Solutions Extension v1.0

A Visual Studio 2022 extension that automatically presents a project filter dialog when opening solutions with multiple projects, allowing you to create filtered solutions with only the projects you need.

Features

  • Automatic Dialog: Shows project filter dialog when opening solutions with multiple projects
  • Project Tree View: Interactive tree view with checkboxes for project selection
  • Smart Dependencies: Automatically selects/deselects dependent projects when you check/uncheck projects
  • Pattern Filtering: Filter projects using wildcard patterns (e.g., *.Test, Core*, *Data*)
  • Bulk Operations: "Select All" and "Clear All" buttons for quick selection
  • Filtered Solutions: Creates new solution files with only selected projects, leaving originals untouched
  • Manual Access: Menu command for manual filtering of already opened solutions

Project Structure

FilteredSolutionsExtension/
├── FilteredSolutionsExtension.csproj
├── source.extension.vsixmanifest
├── Menus.vsct
├── FilteredSolutionsExtensionPackage.cs
├── SolutionEventsHandler.cs
├── SolutionOpeningInterceptor.cs
├── ManualFilterCommand.cs
├── ProjectFilterDialog.xaml
├── ProjectFilterDialog.xaml.cs
├── ProjectTreeItem.cs
├── ProjectNode.cs
├── ProjectInfo.cs
├── SolutionParser.cs
├── FilteredSolutionGenerator.cs
├── FileUtils.cs
├── ErrorHandler.cs
├── DebugHelper.cs
├── ExtensionSettings.cs
├── Properties/
│   └── AssemblyInfo.cs
└── Resources/
    └── FilterSolutionsCommand.png

Technology Stack

  • Target Framework: .NET Framework 4.7.2
  • Visual Studio SDK: 17.0+
  • UI Framework: WPF (XAML)
  • Package Format: VSIX
  • Threading: Async/await patterns with Visual Studio JoinableTaskFactory
  • JSON Serialization: System.Text.Json 9.0.5

Key Features Implementation

1. Automatic Solution Filtering

  • SolutionEventsHandler: Monitors solution opening events
  • SolutionOpeningInterceptor: Alternative approach using running document table events
  • Smart Detection: Only shows dialog for solutions with multiple projects
  • Filtered Solution Detection: Skips dialog for already filtered solutions

2. Interactive Project Selection

  • ProjectFilterDialog: WPF dialog with modern UI
  • TreeView Control: Displays projects with checkboxes
  • Real-time Updates: Live selection count and status updates
  • Project Icons: Visual project type indicators

3. Dependency Management

  • Automatic Selection: Checking a project automatically selects its dependencies
  • Cascading Deselection: Unchecking a project deselects dependent projects
  • Project Reference Parsing: Reads MSBuild project files for accurate dependencies
  • Solution-level Dependencies: Supports both project references and solution dependencies

4. Advanced Filtering

  • Wildcard Support: Use * for pattern matching
  • Case-insensitive: Filtering works regardless of case
  • Real-time Filter: Instant visual filtering as you type
  • Filter Examples:
    • Test* - Projects starting with "Test"
    • *Core* - Projects containing "Core"
    • *.Data - Projects ending with ".Data"

5. Solution Generation

  • FilteredSolutionGenerator: Creates new .sln files
  • Regex-based Parsing: Robust solution file parsing
  • Global Section Filtering: Properly filters project configurations and dependencies
  • Temp Directory: Creates filtered solutions in system temp folder
  • Original Preservation: Never modifies original solution files

Usage Workflow

Automatic Filtering

  1. Open Solution: Use File → Open → Project/Solution
  2. Dialog Appears: Filter dialog shows automatically for multi-project solutions
  3. Select Projects: Use checkboxes, search filter, or bulk selection
  4. Dependencies: Required dependencies are automatically included
  5. Create: Click "Create Filtered Solution" to generate and open filtered solution
  6. Alternative: Click "Open All Projects" to continue with full solution

Manual Filtering

  1. Open Solution: Open any solution normally
  2. Access Menu: Go to File → "Filter Solution Projects..."
  3. Filter Projects: Use the same dialog interface
  4. Generate: Create filtered solution from currently opened solution

Dialog Controls

  • Filter Pattern: Text input with wildcard support
  • Apply Filter/Clear: Apply or reset filtering
  • Select All/Clear All: Bulk selection operations
  • Project Tree: Checkboxes with dependency indicators
  • Selection Count: Real-time count of selected projects
  • Status Bar: Progress and status information

Building the Extension

Prerequisites

  • Visual Studio 2022 with Visual Studio extension development workload
  • .NET Framework 4.7.2 SDK
  • .NET 9.0 SDK

Build Steps

  1. Clone/Download: Get the source code
  2. Open in VS: Open FilteredSolutionsExtension.sln
  3. Restore Packages: NuGet packages will restore automatically
  4. Build: Build → Build Solution (Ctrl+Shift+B)
  5. VSIX Output: Find the .vsix file in bin/Debug or bin/Release

Debug/Test

  1. Set Startup: Set the VSIX project as startup project
  2. Press F5: Launches experimental instance of Visual Studio
  3. Test: Open a multi-project solution to test the extension

Installation

From Build

  1. Build VSIX: Follow build steps above
  2. Install: Double-click the generated .vsix file
  3. Restart: Restart Visual Studio if required

From VSIX File

  1. Double-click: Double-click the .vsix file
  2. VS Installer: Visual Studio Installer will open
  3. Install: Follow installation prompts
  4. Verify: Check Extensions → Manage Extensions

Configuration

Settings (Future Enhancement)

The extension includes ExtensionSettings.cs for future configuration options:

  • Auto-show filter dialog preference
  • Remember last selection per solution
  • Default filter patterns
  • Auto-select dependencies preference
  • Show project paths in tree

Current Behavior

  • Always shows dialog for multi-project solutions
  • Always includes dependencies automatically
  • Creates filtered solutions in temp directory
  • Preserves original solution files

Architecture

Threading Model

  • Async/Await: Modern async patterns throughout
  • UI Thread Safety: Proper thread marshaling for UI operations
  • JoinableTaskFactory: Visual Studio recommended threading
  • Background Processing: Solution parsing on background threads

Error Handling

  • ErrorHandler: Centralized error logging and user notification
  • DebugHelper: Development debugging utilities
  • Graceful Degradation: Continues operation on non-critical errors
  • User Feedback: Clear error messages and status updates

File Operations

  • FileUtils: Async file operations compatible with .NET 4.7.2
  • Solution Parsing: Robust regex-based solution file parsing
  • Project Analysis: MSBuild project file dependency analysis
  • Temp Management: Automatic cleanup of temporary files

Known Limitations

  1. Project Types: Only works with standard MSBuild-based projects
  2. Solution Folders: Solution folders are filtered out during parsing
  3. Complex Dependencies: Some complex project configurations may need manual adjustment
  4. Performance: Large solutions (100+ projects) may take time to parse
  5. Temporary Solutions: Filtered solutions are created in temp directory

Troubleshooting

Common Issues

Dialog doesn't appear

  • Ensure solution has multiple projects
  • Check if solution is already filtered (temp file)
  • Verify extension is installed and enabled

Dependencies not working

  • Check project references in original solution
  • Verify project GUIDs are consistent
  • Look for circular dependencies

Filtered solution won't open

  • Check temp directory permissions
  • Ensure original project files exist
  • Verify project file paths are correct

Extension won't load

  • Confirm Visual Studio 2022 compatibility
  • Check Windows Event Log for errors
  • Verify all dependencies are installed

Debug Information

  • Extension logs to Visual Studio Output window
  • Check debug output for detailed error information
  • Use DebugHelper.GetLogPath() for file-based logging

Future Enhancements

  • Settings Dialog: UI for configuring extension behavior
  • Solution Folder Support: Include solution folders in filtering
  • Template Support: Save and load project selection templates
  • Performance Optimization: Faster parsing for large solutions
  • Integration: Better integration with Solution Explorer
  • Batch Processing: Process multiple solutions at once
  • Export/Import: Share filter configurations between machines

Contributing

  1. Fork: Fork the repository
  2. Branch: Create feature branch
  3. Develop: Make changes following existing patterns
  4. Test: Test with various solution types
  5. Pull Request: Submit PR with description

License

This project is provided as-is for educational and development purposes.

Version History

1.0.0 - Initial Release

  • Core project filtering functionality
  • Automatic dialog on solution open
  • Manual filtering command
  • Dependency management
  • Pattern-based filtering
  • Modern async/await architecture
  • Comprehensive error handling

Happy Coding! 🚀

This extension streamlines your Visual Studio workflow by letting you work with only the projects you need, making large solutions more manageable and improving build times.