feat: Implement nbgv path-filters command for monorepo pathFilters automation#1397
Merged
Conversation
- Register MSBuildLocator at application startup (MainInner) instead of per-command - MSBuildLocator must be registered before any MSBuild code is loaded - Add Microsoft.Build.Locator package reference - Filter out obj/ and bin/ directory files from pathFilters (these are generated) - Fix StyleCop warning SA1507 (multiple blank lines) This ensures the path-filters command correctly uses the installed MSBuild and SDK resolvers when evaluating projects, and includes only source files in the computed pathFilters. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ual project files - Include the directory containing each project (e.g., /A) instead of the .csproj file - Keep individual files for MSBuild imports like Directory.Build.props since these are shared build files not contained in project directories - This makes pathFilters cleaner and more intuitive For example, B's pathFilters now includes /A and /B (directories) plus /Directory.Build.props (shared file) instead of /A/A.csproj and /B/B.csproj. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…n files - Only process version.json files that have at least one MSBuild project - When searching for projects, stop at directories containing other version.json files - This prevents root version.json files with no direct projects from being processed - Each version.json boundary is respected, ensuring clean separation of concerns Example: In a directory structure with root/A/version.json and root/B/version.json, the root version.json is left untouched because all its projects are in subdirectories with their own version.json files. Only A and B are processed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add comprehensive documentation to path-filters.md covering: - When to use path-filters command (monorepos, complex dependencies) - How it works (project discovery, transitive dependencies, shared files) - Important behaviors (orphan skipping, boundary respect, directory inclusion) - Usage examples (check, update commands with options) - Real-world example with multiple projects - CI integration guidance - Add reference in nbgv-cli.md command list linking to path-filters documentation The path-filters command automates computation and validation of pathFilters based on MSBuild project structure, making it easy to maintain correct filters in monorepos with multiple versioned projects. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…paths - Added virtual IsIgnored(path) method to GitContext base class - Implemented in LibGit2Context to check against common .gitignore patterns (bin/, obj/, packages/, .vs/, .vscode/, node_modules/) - This ensures generated files are excluded from pathFilters more comprehensively - Simplistic but effective approach that covers the most common use cases Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…hecking - Replaced manual pattern matching with LibGit2Sharp's built-in ignore checking - This respects all .gitignore patterns in the repository, not just hardcoded directories - Cleaner, more maintainable, and handles all ignore rules correctly - Properly converts absolute paths to repo-relative paths before checking Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the
nbgv path-filterscommand to automate discovery and maintenance ofpathFiltersin monorepo scenarios. This addresses #1396 by leveraging MSBuild's ProjectGraph API to efficiently compute transitive closure of project dependencies.What's New
Two new subcommands:
nbgv path-filters check- Validates thatpathFiltersin allversion.jsonfiles are complete and correctnbgv path-filters update- Automatically computes and updatespathFiltersbased on actual project structureKey Design Decisions
MSBuild ProjectGraph for Dependency Discovery
Respects version.json Boundaries
version.json, stops at any subdirectory that has its ownversion.jsonversion.jsonfrom incorrectly claiming nested projectsIncludes Entire Project Directories
pathFiltersspecify project directories (e.g.,/ProjectA) rather than individual.csprojfilesDirectory.Build.propsare included as specific file pathsRespects .gitignore Rules
Repository.Ignore.IsPathIgnored()to exclude all ignored files (including generated directories likebin/,obj/,packages/).gitignorepatterns configured in the repositoryTransitive Dependency Inclusion
pathFiltersincludes files imported by ADocumentation
Added comprehensive documentation in
docfx/docs/path-filters.mdcovering:Testing
Verified with a test directory containing:
version.json(left untouched as it has no direct projects)version.jsonfiles.propsfilescheckandupdatesubcommands produce correct resultspathFiltersCloses #1396