Skip to content

Commit 87f9f87

Browse files
thomhurstclaude
andcommitted
refactor: Use XML parsing instead of string parsing for project dependencies
Replace fragile string parsing with proper XML parsing using XDocument to extract ProjectReference elements from .csproj files. Benefits: - More robust and reliable parsing - Handles all formatting variations correctly - Platform-independent path handling with Path.GetFileName - Follows the same pattern used elsewhere in the codebase Fixes #1645 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7412b8d commit 87f9f87

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/ModularPipelines.Build/Modules/FindProjectDependenciesModule.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Xml.Linq;
12
using Microsoft.Extensions.Logging;
23
using ModularPipelines.Attributes;
34
using ModularPipelines.Context;
@@ -17,15 +18,19 @@ public class FindProjectDependenciesModule : Module<FindProjectDependenciesModul
1718

1819
foreach (var file in projects.Value!)
1920
{
20-
await foreach (var line in file.ReadLinesAsync(cancellationToken))
21-
{
22-
if (!line.Contains("<ProjectReference"))
23-
{
24-
continue;
25-
}
21+
var doc = await XDocument.LoadAsync(
22+
System.IO.File.OpenRead(file.Path),
23+
LoadOptions.None,
24+
cancellationToken);
2625

27-
var name = line.Split('\\').Last().Split('"').First();
26+
var projectReferences = doc.Descendants()
27+
.Where(e => e.Name.LocalName == "ProjectReference")
28+
.Select(e => e.Attribute("Include")?.Value)
29+
.Where(v => v != null);
2830

31+
foreach (var reference in projectReferences)
32+
{
33+
var name = Path.GetFileName(reference);
2934
var project = projects.Value!.FirstOrDefault(x => x.Name == name);
3035

3136
if (project != null)

0 commit comments

Comments
 (0)