Skip to content

Commit a84f7d8

Browse files
authored
Support package@version syntax in dotnet new install, partial fix for #45422 (#45545)
Progress towards #45422 This adds support for package@version syntax without removing support for package::version syntax. I'll add a follow-up PR in main to add a warning, and then we can remove support for package::version syntax in .NET 11.
1 parent f6b778f commit a84f7d8

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ internal async Task<NewCommandStatus> EnterInstallFlowAsync(InstallCommandArgs a
208208

209209
foreach (string installArg in args.TemplatePackages)
210210
{
211-
string[] splitByColons = installArg.Split(new[] { "::" }, StringSplitOptions.RemoveEmptyEntries);
212-
string identifier = splitByColons[0];
213-
string? version = splitByColons.Length > 1 ? splitByColons[1] : null;
211+
string[] split = installArg.Split(["::"], StringSplitOptions.RemoveEmptyEntries).SelectMany(arg => arg.Split('@', StringSplitOptions.RemoveEmptyEntries)).ToArray();
212+
string identifier = split[0];
213+
string? version = split.Length > 1 ? split[1] : null;
214214
foreach (string expandedIdentifier in InstallRequestPathResolution.ExpandMaskedPath(identifier, _engineEnvironmentSettings))
215215
{
216216
installRequests.Add(new InstallRequest(expandedIdentifier, version, details: details, force: args.Force));

test/dotnet-new.Tests/DotnetNewInstallTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,22 @@ public void CanInstallRemoteNuGetPackage(string commandName)
4242
}
4343

4444
[Theory]
45-
[InlineData("-i")]
46-
[InlineData("install")]
47-
public void CanInstallRemoteNuGetPackage_LatestVariations(string commandName)
45+
[InlineData("::")]
46+
[InlineData("@")]
47+
public void CanInstallRemoteNuGetPackage_LatestVariations(string separator)
4848
{
49+
var commandName = "install";
4950
CommandResult command1 = new DotnetNewCommand(_log, commandName, "Microsoft.DotNet.Common.ProjectTemplates.5.0")
5051
.WithCustomHive(CreateTemporaryFolder(folderName: "Home"))
5152
.WithWorkingDirectory(CreateTemporaryFolder())
5253
.Execute();
5354

54-
CommandResult command2 = new DotnetNewCommand(_log, commandName, "Microsoft.DotNet.Common.ProjectTemplates.5.0::")
55+
CommandResult command2 = new DotnetNewCommand(_log, commandName, $"Microsoft.DotNet.Common.ProjectTemplates.5.0{separator}")
5556
.WithCustomHive(CreateTemporaryFolder(folderName: "Home"))
5657
.WithWorkingDirectory(CreateTemporaryFolder())
5758
.Execute();
5859

59-
CommandResult command3 = new DotnetNewCommand(_log, commandName, "Microsoft.DotNet.Common.ProjectTemplates.5.0::*")
60+
CommandResult command3 = new DotnetNewCommand(_log, commandName, $"Microsoft.DotNet.Common.ProjectTemplates.5.0{separator}*")
6061
.WithCustomHive(CreateTemporaryFolder(folderName: "Home"))
6162
.WithWorkingDirectory(CreateTemporaryFolder())
6263
.Execute();

0 commit comments

Comments
 (0)