diff --git a/NuGet.config b/NuGet.config
index 4b2250e637..bccec33d8e 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -4,5 +4,6 @@
+
diff --git a/eng/Set-DotnetVersions.ps1 b/eng/Set-DotnetVersions.ps1
index 5e7d6d064c..53f8ff8935 100644
--- a/eng/Set-DotnetVersions.ps1
+++ b/eng/Set-DotnetVersions.ps1
@@ -149,5 +149,5 @@ if ($AzdoVariableName) {
Write-Host "##vso[task.setvariable variable=$AzdoVariableName]$updateDepsArgs"
}
else {
- & dotnet run --project $PSScriptRoot/update-dependencies/update-dependencies.csproj @updateDepsArgs
+ & dotnet run --project $PSScriptRoot/update-dependencies/update-dependencies.csproj specific @updateDepsArgs
}
diff --git a/eng/update-dependencies/BaseCommand.cs b/eng/update-dependencies/BaseCommand.cs
new file mode 100644
index 0000000000..e94413dc5d
--- /dev/null
+++ b/eng/update-dependencies/BaseCommand.cs
@@ -0,0 +1,45 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.CommandLine;
+using System.CommandLine.NamingConventionBinder;
+using System.Threading.Tasks;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+
+namespace Dotnet.Docker;
+
+public abstract class BaseCommand() where TOptions : IOptions
+{
+ public abstract Task ExecuteAsync(TOptions options);
+
+ public static void Register(IServiceCollection serviceCollection) where T : BaseCommand
+ {
+ serviceCollection.AddSingleton, T>();
+ }
+
+ public static Command Create(string name, string description)
+ {
+ var command = new Command(name, description);
+
+ foreach (var option in TOptions.Options)
+ {
+ command.Add(option);
+ }
+
+ foreach (var argument in TOptions.Arguments)
+ {
+ command.Add(argument);
+ }
+
+ command.Action = Handler;
+ return command;
+ }
+
+ private static BindingHandler Handler =>
+ CommandHandler.Create(async (options, host) =>
+ {
+ var thisCommand = host.Services.GetRequiredService>();
+ return await thisCommand.ExecuteAsync(options);
+ });
+}
diff --git a/eng/update-dependencies/BaseUrlUpdater.cs b/eng/update-dependencies/BaseUrlUpdater.cs
index 647c7f2d69..5d2c97826f 100644
--- a/eng/update-dependencies/BaseUrlUpdater.cs
+++ b/eng/update-dependencies/BaseUrlUpdater.cs
@@ -15,20 +15,20 @@ namespace Dotnet.Docker;
internal class BaseUrlUpdater : FileRegexUpdater
{
private const string BaseUrlGroupName = "BaseUrlValue";
- private readonly Options _options;
+ private readonly SpecificCommandOptions _options;
private readonly JObject _manifestVariables;
- public BaseUrlUpdater(string repoRoot, Options options)
+ public BaseUrlUpdater(string repoRoot, SpecificCommandOptions options)
{
- Path = System.IO.Path.Combine(repoRoot, UpdateDependencies.VersionsFilename);
+ Path = System.IO.Path.Combine(repoRoot, SpecificCommand.VersionsFilename);
VersionGroupName = BaseUrlGroupName;
Regex = ManifestHelper.GetManifestVariableRegex(
ManifestHelper.GetBaseUrlVariableName(options.DockerfileVersion, options.SourceBranch, options.VersionSourceName),
$"(?<{BaseUrlGroupName}>.+)");
_options = options;
- _manifestVariables = (JObject?)ManifestHelper.LoadManifest(UpdateDependencies.VersionsFilename)["variables"] ??
- throw new InvalidOperationException($"'{UpdateDependencies.VersionsFilename}' property missing in '{UpdateDependencies.VersionsFilename}'"); ;
+ _manifestVariables = (JObject?)ManifestHelper.LoadManifest(SpecificCommand.VersionsFilename)["variables"] ??
+ throw new InvalidOperationException($"'{SpecificCommand.VersionsFilename}' property missing in '{SpecificCommand.VersionsFilename}'"); ;
}
protected override string TryGetDesiredValue(IEnumerable dependencyInfos, out IEnumerable usedDependencyInfos)
diff --git a/eng/update-dependencies/DockerfileShaUpdater.cs b/eng/update-dependencies/DockerfileShaUpdater.cs
index 986c1ba704..0e522c7f10 100644
--- a/eng/update-dependencies/DockerfileShaUpdater.cs
+++ b/eng/update-dependencies/DockerfileShaUpdater.cs
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-//
using System;
using System.Collections.Generic;
@@ -38,13 +37,13 @@ public class DockerfileShaUpdater : FileRegexUpdater
private readonly string? _buildVersion;
private readonly string _arch;
private readonly string _os;
- private readonly Options _options;
+ private readonly SpecificCommandOptions _options;
private readonly string _versions;
private readonly Dictionary _urls;
private readonly Lazy _manifestVariables;
public DockerfileShaUpdater(
- string productName, string dockerfileVersion, string? buildVersion, string arch, string os, string versions, Options options)
+ string productName, string dockerfileVersion, string? buildVersion, string arch, string os, string versions, SpecificCommandOptions options)
{
_productName = productName;
_dockerfileVersion = new Version(dockerfileVersion);
@@ -74,10 +73,10 @@ public DockerfileShaUpdater(
() =>
{
const string VariablesProperty = "variables";
- JToken? variables = ManifestHelper.LoadManifest(UpdateDependencies.VersionsFilename)[VariablesProperty];
+ JToken? variables = ManifestHelper.LoadManifest(SpecificCommand.VersionsFilename)[VariablesProperty];
if (variables is null)
{
- throw new InvalidOperationException($"'{VariablesProperty}' property missing in '{UpdateDependencies.VersionsFilename}'");
+ throw new InvalidOperationException($"'{VariablesProperty}' property missing in '{SpecificCommand.VersionsFilename}'");
}
return (JObject)variables;
});
@@ -92,23 +91,14 @@ public DockerfileShaUpdater(
}
public static IEnumerable CreateUpdaters(
- string productName, string dockerfileVersion, string repoRoot, Options options)
+ string productName, string dockerfileVersion, string repoRoot, SpecificCommandOptions options)
{
- string versionsPath = System.IO.Path.Combine(repoRoot, UpdateDependencies.VersionsFilename);
+ string versionsPath = System.IO.Path.Combine(repoRoot, SpecificCommand.VersionsFilename);
string versions = File.ReadAllText(versionsPath);
// The format of the sha variable name is '||||sha'.
// The 'os' and 'arch' segments are optional.
- string shaVariablePattern;
- if (productName == NetStandard21TargetingPack)
- {
- // NetStandard targeting pack is not associated with a specific Dockerfile version
- shaVariablePattern = $"\"(?<{ShaVariableGroupName}>{Regex.Escape(productName)}.*\\|sha)\":";
- }
- else
- {
- shaVariablePattern = $"\"(?<{ShaVariableGroupName}>{Regex.Escape(productName)}\\|{Regex.Escape(dockerfileVersion)}.*\\|sha)\":";
- }
+ string shaVariablePattern = $"\"(?<{ShaVariableGroupName}>{Regex.Escape(productName)}\\|{Regex.Escape(dockerfileVersion)}.*\\|sha)\":";
Regex shaVariableRegex = new(shaVariablePattern);
@@ -151,7 +141,7 @@ public static IEnumerable CreateUpdaters(
// Remove Aspire Dashboard case once https://github.com/dotnet/aspire/issues/2035 is fixed.
string archiveExt = _os.Contains("win") || _productName.Contains("aspire-dashboard") ? "zip" : "tar.gz";
string versionDir = _buildVersion ?? "";
- string versionFile = UpdateDependencies.ResolveProductVersion(versionDir, _options);
+ string versionFile = SpecificCommand.ResolveProductVersion(versionDir, _options);
string downloadUrl = _urls[_productName]
.Replace("$DOTNET_BASE_URL", baseUrl)
@@ -416,7 +406,7 @@ Other times the first line is the first checksum entry. This
return checksumEntries;
}
- private static string? GetBuildVersion(string productName, string dockerfileVersion, string variables, Options options)
+ private static string? GetBuildVersion(string productName, string dockerfileVersion, string variables, SpecificCommandOptions options)
{
string? buildVersion;
if (options.ProductVersions.TryGetValue(productName, out string? version))
diff --git a/eng/update-dependencies/IOptions.cs b/eng/update-dependencies/IOptions.cs
new file mode 100644
index 0000000000..cf90739422
--- /dev/null
+++ b/eng/update-dependencies/IOptions.cs
@@ -0,0 +1,13 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Collections.Generic;
+using System.CommandLine;
+
+namespace Dotnet.Docker;
+
+public interface IOptions
+{
+ public static abstract List