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
{{ message }}
Repository navigation
C#: Attempt to parse as XML instead of reading everything as text in the FileContent processing. - #22915
Instead of searching through all files (including source code files) we attempt to read the files as XML instead for detecting framework and package dependencies (and other project related settings). This will
Implicitly enable "fail-fast" (as an exception will be thrown as non-XML file content is found).
Make it easier to extend the logic for detecting certain properties.
Note, that this change impacts the semantics of the heuristic and we expect that this generally improves the precision of the heuristic detection of project properties.
Only XML file content is taken into consideration.
XML split across multiple lines will now be parsed and detected correctly.
Comments across multiple lines will be handled correctly.
<Sdk Name="..."> is now taken into consideration.
We don't do any handling of encoding (pointed out by CoPilot) and I don't think that is worth incorporating unless we see a concrete use-case.
Furthermore, this is expected to improve performance: We do less parsing of text as the XmlReader gives up and throws an exception, as soon as non-XML is encountered (before we read all text from all files and did regular expression matching).
DCA looks good
Drastic reduction in the number of calls with missing call target for dotnet/efcore.
michaelnebel
changed the title
C#: Use an XML parser instead of reading everything as text in the FileContent processing.
C#: Attempt to parse as XML instead of reading everything as text in the FileContent processing.
Oct 28, 2026
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Case-sensitive MSBuild element matching ignores valid settings, and failed XML parsing leaves partial dependencies and settings committed, allowing invalid files to affect restoration.
Replaces text-based dependency detection in the C# extractor with streaming XML parsing, improving handling of project settings, multiline elements, and XML comments.
Changes:
Replaces regular expressions with XmlReader for detecting packages and project settings.
Changes file reading to streams and logs XML parsing failures.
Expands tests for XML syntax, namespaces, comments, packages.config, and invalid input.
An otherwise valid, ASCII-only project declaring encoding="windows-1252" is now skipped at its declaration unless a code-page provider is registered. The extractor targets .NET 10 and does not register one, so this loses package and framework references that the old StreamReader path found. Register CodePagesEncodingProvider before creating XML readers, while keeping stream-based decoding for correctly declared encodings.
Projects that declare their SDK with <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" /> now leave IsSdkProjectStructureUsed false; the removed regex recognized this form. In repositories using only these imports, that skips Razor/.resx source generation and falls back to the executing runtime. Check the Sdk attribute in this branch as well, and add an import-form regression test.
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
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.
Instead of searching through all files (including source code files) we attempt to read the files as XML instead for detecting framework and package dependencies (and other project related settings). This will
Note, that this change impacts the semantics of the heuristic and we expect that this generally improves the precision of the heuristic detection of project properties.
<Sdk Name="...">is now taken into consideration.Furthermore, this is expected to improve performance: We do less parsing of text as the
XmlReadergives up and throws an exception, as soon as non-XML is encountered (before we read all text from all files and did regular expression matching).DCA looks good
dotnet/efcore.