From d1aa8901f9d797147941b39e29bdf4f52e16e81b Mon Sep 17 00:00:00 2001 From: Forgind <12969783+Forgind@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:01:52 -0800 Subject: [PATCH 1/3] Support split-by-at --- .../TemplatePackageCoordinator.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs b/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs index 313a7fd31501..f16ab8c8d75a 100644 --- a/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs +++ b/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs @@ -207,9 +207,11 @@ internal async Task EnterInstallFlowAsync(InstallCommandArgs a foreach (string installArg in args.TemplatePackages) { - string[] splitByColons = installArg.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries); - string identifier = splitByColons[0]; - string? version = splitByColons.Length > 1 ? splitByColons[1] : null; + string[] splitByColons = installArg.Split(["::"], StringSplitOptions.RemoveEmptyEntries); + string[] splitByAt = installArg.Split('@', StringSplitOptions.RemoveEmptyEntries); + string[] split = splitByColons.Length > splitByAt.Length ? splitByColons : splitByAt; + string identifier = split[0]; + string? version = split.Length > 1 ? split[1] : null; foreach (string expandedIdentifier in InstallRequestPathResolution.ExpandMaskedPath(identifier, _engineEnvironmentSettings)) { installRequests.Add(new InstallRequest(expandedIdentifier, version, details: details, force: args.Force)); From 50d556e29320c270f2046bc6185c5777db6306f6 Mon Sep 17 00:00:00 2001 From: Forgind <12969783+Forgind@users.noreply.github.com> Date: Wed, 18 Dec 2024 17:35:37 -0800 Subject: [PATCH 2/3] Support stupid test --- .../TemplatePackageCoordinator.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs b/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs index f16ab8c8d75a..3e59dc154bc7 100644 --- a/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs +++ b/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs @@ -209,7 +209,10 @@ internal async Task EnterInstallFlowAsync(InstallCommandArgs a { string[] splitByColons = installArg.Split(["::"], StringSplitOptions.RemoveEmptyEntries); string[] splitByAt = installArg.Split('@', StringSplitOptions.RemoveEmptyEntries); - string[] split = splitByColons.Length > splitByAt.Length ? splitByColons : splitByAt; + string[] split = splitByColons.Length > splitByAt.Length ? splitByColons : + splitByAt.Length > splitByColons.Length ? splitByAt : + splitByColons[0].Length < splitByAt[0].Length ? splitByColons : + splitByAt; string identifier = split[0]; string? version = split.Length > 1 ? split[1] : null; foreach (string expandedIdentifier in InstallRequestPathResolution.ExpandMaskedPath(identifier, _engineEnvironmentSettings)) From 00bba930e6e270d5fbca46cf4ff9fe9661e10a6d Mon Sep 17 00:00:00 2001 From: Forgind <12969783+Forgind@users.noreply.github.com> Date: Fri, 20 Dec 2024 16:14:11 -0800 Subject: [PATCH 3/3] Change split mechanism and add test --- .../TemplatePackageCoordinator.cs | 7 +------ test/dotnet-new.Tests/DotnetNewInstallTests.cs | 11 ++++++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs b/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs index 3e59dc154bc7..9e04501f49d1 100644 --- a/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs +++ b/src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs @@ -207,12 +207,7 @@ internal async Task EnterInstallFlowAsync(InstallCommandArgs a foreach (string installArg in args.TemplatePackages) { - string[] splitByColons = installArg.Split(["::"], StringSplitOptions.RemoveEmptyEntries); - string[] splitByAt = installArg.Split('@', StringSplitOptions.RemoveEmptyEntries); - string[] split = splitByColons.Length > splitByAt.Length ? splitByColons : - splitByAt.Length > splitByColons.Length ? splitByAt : - splitByColons[0].Length < splitByAt[0].Length ? splitByColons : - splitByAt; + string[] split = installArg.Split(["::"], StringSplitOptions.RemoveEmptyEntries).SelectMany(arg => arg.Split('@', StringSplitOptions.RemoveEmptyEntries)).ToArray(); string identifier = split[0]; string? version = split.Length > 1 ? split[1] : null; foreach (string expandedIdentifier in InstallRequestPathResolution.ExpandMaskedPath(identifier, _engineEnvironmentSettings)) diff --git a/test/dotnet-new.Tests/DotnetNewInstallTests.cs b/test/dotnet-new.Tests/DotnetNewInstallTests.cs index 2ebcaff0bb44..9f515bfffb10 100644 --- a/test/dotnet-new.Tests/DotnetNewInstallTests.cs +++ b/test/dotnet-new.Tests/DotnetNewInstallTests.cs @@ -42,21 +42,22 @@ public void CanInstallRemoteNuGetPackage(string commandName) } [Theory] - [InlineData("-i")] - [InlineData("install")] - public void CanInstallRemoteNuGetPackage_LatestVariations(string commandName) + [InlineData("::")] + [InlineData("@")] + public void CanInstallRemoteNuGetPackage_LatestVariations(string separator) { + var commandName = "install"; CommandResult command1 = new DotnetNewCommand(_log, commandName, "Microsoft.DotNet.Common.ProjectTemplates.5.0") .WithCustomHive(CreateTemporaryFolder(folderName: "Home")) .WithWorkingDirectory(CreateTemporaryFolder()) .Execute(); - CommandResult command2 = new DotnetNewCommand(_log, commandName, "Microsoft.DotNet.Common.ProjectTemplates.5.0::") + CommandResult command2 = new DotnetNewCommand(_log, commandName, $"Microsoft.DotNet.Common.ProjectTemplates.5.0{separator}") .WithCustomHive(CreateTemporaryFolder(folderName: "Home")) .WithWorkingDirectory(CreateTemporaryFolder()) .Execute(); - CommandResult command3 = new DotnetNewCommand(_log, commandName, "Microsoft.DotNet.Common.ProjectTemplates.5.0::*") + CommandResult command3 = new DotnetNewCommand(_log, commandName, $"Microsoft.DotNet.Common.ProjectTemplates.5.0{separator}*") .WithCustomHive(CreateTemporaryFolder(folderName: "Home")) .WithWorkingDirectory(CreateTemporaryFolder()) .Execute();