Skip to content

Commit bac95cb

Browse files
committed
fix issue with Directory.packages.props detection
1 parent 89c8e5c commit bac95cb

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

src/PackageUpdate/FileSystem.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
static class FileSystem
22
{
3+
public static string? FindPropsFile(string startDirectory, string stopDirectory)
4+
{
5+
var stop = Path.TrimEndingDirectorySeparator(Path.GetFullPath(stopDirectory));
6+
for (var current = new DirectoryInfo(startDirectory); current is not null; current = current.Parent)
7+
{
8+
var candidate = Path.Combine(current.FullName, "Directory.Packages.props");
9+
if (File.Exists(candidate))
10+
{
11+
return candidate;
12+
}
13+
14+
if (string.Equals(current.FullName, stop, StringComparison.OrdinalIgnoreCase))
15+
{
16+
break;
17+
}
18+
}
19+
20+
return null;
21+
}
22+
323
public static IEnumerable<string> FindSolutions(string directory)
424
{
525
foreach (var solution in EnumerateFiles(directory, "*.sln"))
@@ -61,4 +81,4 @@ static IEnumerable<string> GetDirectories(string directory)
6181
return [];
6282
}
6383
}
64-
}
84+
}

src/PackageUpdate/Program.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static async Task Inner(string directory, string? package, bool build)
2828
continue;
2929
}
3030

31-
await TryProcessSolution(cache, solution, package, build);
31+
await TryProcessSolution(cache, solution, package, build, directory);
3232
}
3333

3434
// Tool manifests are scanned independently of solutions, since `.config/dotnet-tools.json`
@@ -52,11 +52,11 @@ static async Task Inner(string directory, string? package, bool build)
5252
Log.Information("Completed in {Elapsed}", Formatter.FormatElapsed(totalStopwatch.Elapsed));
5353
}
5454

55-
static async Task TryProcessSolution(SourceCacheContext cache, string solution, string? package, bool build)
55+
static async Task TryProcessSolution(SourceCacheContext cache, string solution, string? package, bool build, string targetDirectory)
5656
{
5757
try
5858
{
59-
await ProcessSolution(cache, solution, package, build);
59+
await ProcessSolution(cache, solution, package, build, targetDirectory);
6060
}
6161
catch (Exception e)
6262
{
@@ -103,7 +103,7 @@ static async Task ProcessToolManifest(SourceCacheContext cache, string manifest,
103103
Log.Information(" Updated in {Elapsed}", Formatter.FormatElapsed(stopwatch.Elapsed));
104104
}
105105

106-
static async Task ProcessSolution(SourceCacheContext cache, string solution, string? package, bool build)
106+
static async Task ProcessSolution(SourceCacheContext cache, string solution, string? package, bool build, string targetDirectory)
107107
{
108108
if (Excluder.ShouldExclude(solution))
109109
{
@@ -115,20 +115,19 @@ static async Task ProcessSolution(SourceCacheContext cache, string solution, str
115115

116116
var solutionDirectory = Directory.GetParent(solution)!.FullName;
117117

118-
var props = Path.Combine(solutionDirectory, "Directory.Packages.props");
119-
if (!File.Exists(props))
118+
var propsLocation = FileSystem.FindPropsFile(solutionDirectory, targetDirectory);
119+
if (propsLocation is null)
120120
{
121121
Log.Error(" Only central packages supported. Skipping: {Solution}", solution);
122122
return;
123123
}
124124

125125
var stopwatch = Stopwatch.StartNew();
126-
await Updater.Update(cache, props, package);
126+
await Updater.Update(cache, propsLocation, package);
127127
Log.Information(" Updated in {Elapsed}", Formatter.FormatElapsed(stopwatch.Elapsed));
128128

129129
if (build)
130130
{
131131
await DotnetStarter.Build(solution);
132132
}
133133
}
134-

0 commit comments

Comments
 (0)