Skip to content

Simplify content file globbing and remove FileProviders.Abstractions and Primitives from VSIX - #7338

Merged
donnie-msft merged 8 commits into
devfrom
dev-donnie-msft-14686
May 18, 2026
Merged

donnie-msft merged 8 commits into
devfrom
dev-donnie-msft-14686

Conversation

@donnie-msft

@donnie-msft donnie-msft commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

Bug

Fixes: NuGet/Home#14686
Fixes: NuGet/Home#12696

Description

Removes Microsoft.Extensions.FileProviders.Abstractions.dll and Microsoft.Extensions.Primitives.dll from the VSIX by eliminating the code dependency on them.

What changed

  • Replaced the custom virtual filesystem adapter (SingleFileProvider, FileProviderGlobbingDirectory,
    FileProviderGlobbingFile, VirtualFileInfo) with a direct call to matcher.Match("ROOT", relativePath). No custom classes needed.
  • Deleted 4 source files (~370 lines) — net reduction of ~370 lines.
  • Removed Microsoft.Extensions.FileProviders.Abstractions package reference from NuGet.Commands.csproj
    and Directory.Packages.props.
  • Updated .vsixinclude, .vsixignore, .swr, and ilmerge.props to exclude the two removed assemblies.

What stays

  • Microsoft.Extensions.FileSystemGlobbing remains — it provides the Matcher class used for content file glob pattern
    matching.

Performance

Benchmarked the content file globbing hot path across 2,428 packages from the global packages folder (20,540 match operations per iteration):

Approach Mean Allocated
Old code (4 classes + IFileProvider) 42.66 ms 84.21 MB
SingleFileDirectory Approach 32.94 ms 64.20 MB
New code — Match("ROOT", path) 28.61 ms 45.46 MB

The new approach is ~25% faster and allocates ~46% less memory by using Matcher.Match("ROOT", relativePath) directly, avoiding IFileProvider indirection and virtual file info object creation entirely.

Validation

Validated on a clean VM (VS installed from Apex & E2E pipeline bootstrapper, MSBuild 18.7.0-preview) that the refactored
content file globbing produces identical restore output.

  • Created a test project referencing 12 packages with content files spanning a variety of nuspec globbing patterns (recursive wildcards, backslash separators, framework-scoped paths, include+exclude combinations, etc.).
  • Compared the contentFiles section of project.assets.json between stock SDK NuGet and this branch.
  • Results (831 content file entries compared):
    • ✅ msbuild -t:Restore (branch CLI) — identical to baseline
    • ✅ VS auto-restore (branch VSIX) — identical to baseline

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests - No - instead I manually validated with a bunch of different Contentfile Include/Exclude patterns as described above.
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@donnie-msft donnie-msft changed the title Simplify content file globbing and remove FileProviders.Abstractions and Primitives from VSIX [Draft] Simplify content file globbing and remove FileProviders.Abstractions and Primitives from VSIX Apr 28, 2026
@donnie-msft donnie-msft changed the title [Draft] Simplify content file globbing and remove FileProviders.Abstractions and Primitives from VSIX Simplify content file globbing and remove FileProviders.Abstractions and Primitives from VSIX Apr 29, 2026
@donnie-msft
donnie-msft marked this pull request as ready for review April 29, 2026 21:05
@donnie-msft
donnie-msft requested a review from a team as a code owner April 29, 2026 21:05
zivkan
zivkan previously approved these changes Apr 30, 2026

@zivkan zivkan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW, I'm not a fan of the AI generated PR description. It duplicated some information, and gave some information that I consider not helpful as a reviewer. I feel like it kind of misses the point, or at least put me on slightly the wrong mental context, when thinking about the manual testing that happened on the VM (the focus was to test the removed assemblies didn't cause failures on msbuild restore, not to do exhaustive edge case testing, which really should be done with unit tests, not manual tests).

@donnie-msft

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, @zivkan ! Updated the Validation section in the PR Description to be more focused on the validation of restore, not necessarily edge cases for content file patterns.

@donnie-msft
donnie-msft requested review from nkolev92 and zivkan May 2, 2026 00:21
@jeffkl
jeffkl self-requested a review May 5, 2026 22:38
donnie-msft and others added 6 commits May 7, 2026 19:11
Benchmark results (20,540 match operations per iteration):

| Approach                          | Mean     | Allocated |
|---------------------------------- |---------:|----------:|
| Branch_MatchRelativePath (old)    | 73.41 ms | 135.87 MB |
| Dev_ExecuteWithFileProvider       | 38.37 ms |  84.21 MB |
| Proposed_Split (SingleFileDir)    | 31.21 ms |  64.20 MB |
| MatchRoot_RelativePath            | 28.61 ms |  45.46 MB |
| Proposed_Span                     | 35.07 ms |  70.78 MB |

matcher.Match("ROOT", relativePath) is the fastest and simplest.

Co-authored-by: Copilot <[email protected]>
Reviewer feedback: matcher.Match("ROOT", relativePath) is simpler
and benchmarks show it's the fastest approach (~28ms vs ~31ms for
SingleFileDirectory, ~73ms for the old Match(path) without root).

Deletes SingleFileDirectory.cs — no longer needed.

Co-authored-by: Copilot <[email protected]>
…leProvider"

This reverts commit 8bc5fa537805740ec759d4a2d9e24048f87514af.
@donnie-msft
donnie-msft force-pushed the dev-donnie-msft-14686 branch from 17a02e8 to 1bffe08 Compare May 8, 2026 02:12
nkolev92
nkolev92 previously approved these changes May 8, 2026
@donnie-msft

Copy link
Copy Markdown
Contributor Author

@copilot some tests failed. Can you investigate this error and attempt a fix in this PR?:

Error message
Assert.True() Failure
Expected: True
Actual: False
Stack trace
at NuGet.Commands.Test.ContentFilesTests.<ContentFiles_NuspecContentFilesGlobbingSupportExcludeDirSet>d__13.MoveNext()

Copilot AI commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

@copilot some tests failed. Can you investigate this error and attempt a fix in this PR?:

Error message...

Fixed in dd1a9ad. I reproduced the ContentFilesTests failures, updated ContentFileUtils to apply a synthetic matcher root consistently to both patterns and candidate paths (while preserving empty/.. patterns), and re-ran the targeted suite: ContentFilesTests now pass (26/26).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • data.nuget.org
    • Triggering command: /usr/bin/dotnet dotnet test test/NuGet.Core.Tests/NuGet.Commands.Test/NuGet.Commands.Test.csproj --filter FullyQualifiedName~ContentFilesTests -v minimal (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@donnie-msft
donnie-msft requested a review from nkolev92 May 9, 2026 01:37

@zivkan zivkan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I ❤️ perf. 🚗 ➡️ 🚀

@dotnet-policy-service dotnet-policy-service Bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label May 17, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@dotnet-policy-service dotnet-policy-service Bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label May 18, 2026
@donnie-msft
donnie-msft merged commit 2e2826c into dev May 18, 2026
17 of 18 checks passed
@donnie-msft
donnie-msft deleted the dev-donnie-msft-14686 branch May 18, 2026 20:39
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.

Investigate removing Microsoft.Extensions.* assemblies from the VSIX Perf: ContentFileUtils should cache/reuse virtual file instances

5 participants