Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/PackageUpdate/FileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
static class FileSystem
{
public static string? FindPropsFile(string startDirectory, string stopDirectory)
{
var stop = Path.TrimEndingDirectorySeparator(Path.GetFullPath(stopDirectory));
for (var current = new DirectoryInfo(startDirectory); current is not null; current = current.Parent)
{
var candidate = Path.Combine(current.FullName, "Directory.Packages.props");
if (File.Exists(candidate))
{
return candidate;
}

if (string.Equals(current.FullName, stop, StringComparison.OrdinalIgnoreCase))
{
break;
}
}

return null;
}

public static IEnumerable<string> FindSolutions(string directory)
{
foreach (var solution in EnumerateFiles(directory, "*.sln"))
Expand Down Expand Up @@ -61,4 +81,4 @@ static IEnumerable<string> GetDirectories(string directory)
return [];
}
}
}
}
15 changes: 7 additions & 8 deletions src/PackageUpdate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static async Task Inner(string directory, string? package, bool build)
continue;
}

await TryProcessSolution(cache, solution, package, build);
await TryProcessSolution(cache, solution, package, build, directory);
}

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

static async Task TryProcessSolution(SourceCacheContext cache, string solution, string? package, bool build)
static async Task TryProcessSolution(SourceCacheContext cache, string solution, string? package, bool build, string targetDirectory)
{
try
{
await ProcessSolution(cache, solution, package, build);
await ProcessSolution(cache, solution, package, build, targetDirectory);
}
catch (Exception e)
{
Expand Down Expand Up @@ -103,7 +103,7 @@ static async Task ProcessToolManifest(SourceCacheContext cache, string manifest,
Log.Information(" Updated in {Elapsed}", Formatter.FormatElapsed(stopwatch.Elapsed));
}

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

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

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

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

if (build)
{
await DotnetStarter.Build(solution);
}
}

Loading