You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docfx/docs/path-filters.md
+135Lines changed: 135 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,3 +57,138 @@ Multiple path filters may also be specified. The order is irrelevant. After a pa
57
57
|`/root-file.txt`<br>`:/dir/file.txt`| File will be included. Path is absolute (i.e., relative to the root of the repository). |
58
58
|`:!bar.txt`<br>`:^../foo/baz.txt`| File will be excluded. Path is relative to the `version.json` file. `:!` and `:^` prefixes are synonymous. |
59
59
|`:!/root-file.txt`| File will be excluded. Path is absolute (i.e., relative to the root of the repository). |
60
+
61
+
## Managing path filters with `nbgv path-filters`
62
+
63
+
For repositories with multiple projects and version.json files, manually maintaining `pathFilters` can be error-prone. The `nbgv path-filters` command automates this process by analyzing your MSBuild project structure and computing the correct path filters based on project references and shared build files.
64
+
65
+
### When to use path-filters command
66
+
67
+
Use the `nbgv path-filters` command in the following scenarios:
68
+
69
+
-**Monorepo with multiple projects** - You have multiple projects in different directories, each with their own `version.json`
70
+
-**Complex project dependencies** - Projects reference each other, and you need path filters to reflect these dependencies
71
+
-**Shared build files** - You use `Directory.Build.props` or other shared MSBuild imports that should be tracked by multiple projects
72
+
-**Maintaining accuracy** - You want to ensure path filters automatically stay in sync with your project structure
73
+
74
+
### How it works
75
+
76
+
The `nbgv path-filters` command uses the MSBuild project graph API to:
77
+
78
+
1.**Discover project files** - Finds all MSBuild project files (`.csproj`, `.vbproj`, etc.) associated with each `version.json`
79
+
2.**Compute transitive dependencies** - Uses the MSBuild project graph to determine the complete set of projects that each project depends on
80
+
3.**Include shared build files** - Identifies MSBuild imports like `Directory.Build.props` that reside within the repository
81
+
4.**Respect boundaries** - Stops searching for projects at directories containing their own `version.json` files, ensuring clean separation of concerns
82
+
5.**Generate path filters** - Converts the discovered projects and files into appropriate `pathFilters` entries
83
+
84
+
### Important behaviors
85
+
86
+
-**Only processes version.json files with projects** - A `version.json` file with no associated MSBuild projects is skipped and left unchanged
87
+
-**Respects version.json hierarchy** - When searching for projects under a `version.json`, the search stops at subdirectories that have their own `version.json` files
88
+
-**Includes project directories** - Path filters include entire project directories (e.g., `/ProjectA`) rather than individual `.csproj` files so that all source changes under those directories result in a new version of the project
89
+
-**Filters ignored files** - Automatically excludes files that match `.gitignore` patterns (including generated directories like `obj/` and `bin/`)
90
+
91
+
### Usage
92
+
93
+
#### Check current path filters
94
+
95
+
To see what path filters should be present without making changes:
96
+
97
+
```ps1
98
+
nbgv path-filters check
99
+
```
100
+
101
+
This command will:
102
+
- Compare the computed path filters against what's currently in each `version.json`
103
+
- Display mismatches (missing or extra filters)
104
+
- Exit with non-zero code if any mismatches are found (useful for CI validation)
105
+
106
+
#### Update path filters
107
+
108
+
To automatically compute and update all `version.json` files:
109
+
110
+
```ps1
111
+
nbgv path-filters update
112
+
```
113
+
114
+
This command will:
115
+
- Compute the correct path filters for each `version.json`
116
+
- Update each file that needs changes
117
+
- Display which files were updated
118
+
- Skip any `version.json` files that have no associated projects
119
+
120
+
#### Specify which version.json files to process
121
+
122
+
By default, both commands search from the current directory. You can specify specific paths:
**Root version.json** - Left unchanged (has no projects directly under it)
156
+
157
+
**ProjectA/version.json**:
158
+
```json
159
+
{
160
+
"version": "2.0",
161
+
"pathFilters": [
162
+
"/ProjectA",
163
+
"/Directory.Build.props"
164
+
]
165
+
}
166
+
```
167
+
168
+
**ProjectB/version.json**:
169
+
```json
170
+
{
171
+
"version": "3.0",
172
+
"pathFilters": [
173
+
"/ProjectA",
174
+
"/ProjectB",
175
+
"/Directory.Build.props"
176
+
]
177
+
}
178
+
```
179
+
180
+
Note that ProjectB's filters include ProjectA because ProjectB depends on it. Any change to ProjectA's source files will now correctly trigger a version bump for ProjectB as well.
181
+
182
+
### CI Integration
183
+
184
+
You can use the `path-filters check` command in your CI pipeline to validate that `pathFilters` are correctly maintained:
185
+
186
+
```ps1
187
+
nbgv path-filters check
188
+
if ($LASTEXITCODE -ne 0) {
189
+
Write-Error "Path filters are out of date. Run 'nbgv path-filters update' locally."
190
+
exit 1
191
+
}
192
+
```
193
+
194
+
This ensures that developers keep path filters in sync with project structure changes.
0 commit comments