Skip to content

Skip splitting for paths Fixes #48794 #48874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ internal async Task<NewCommandStatus> EnterInstallFlowAsync(InstallCommandArgs a

foreach (string installArg in args.TemplatePackages)
{
Copy link
Preview

Copilot AI May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment to explain that the check is used to skip splitting for arguments that represent existing file or directory paths, which will help future maintainers understand the purpose of this logic.

Suggested change
{
{
// Check if the argument represents an existing file or directory path.
// If it is a path, skip splitting the argument, as it is already in the desired format.

Copilot uses AI. Check for mistakes.

string[] split = installArg.Split(["::"], StringSplitOptions.RemoveEmptyEntries).SelectMany(arg => arg.Split('@', StringSplitOptions.RemoveEmptyEntries)).ToArray();
bool isPath = File.Exists(installArg) || Directory.Exists(installArg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there something to check if it is a path? Like, something related to that RelativePath utility thing. Because you shouldn't need to check if something is on-disk to know if the argument is a path or not.

Copy link
Member

@nagilson nagilson May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could call http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx Path.GetFullPath and catch the exception to see if it's not a path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that I agree with this. If you want to dotnet new install something in your current directory, it would be very hard to tell (without checking if it exists) that it's a path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if you were to just check for an exception from Path.GetFullPath, I think ~any package would show up as a path

string[] split = isPath ? new[] { installArg } : installArg.Split(["::"], StringSplitOptions.RemoveEmptyEntries).SelectMany(arg => arg.Split('@', StringSplitOptions.RemoveEmptyEntries)).ToArray();
string identifier = split[0];
string? version = split.Length > 1 ? split[1] : null;

Expand Down
17 changes: 17 additions & 0 deletions test/dotnet-new.IntegrationTests/DotnetNewInstallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ public void CanInstallRemoteNuGetPackage(string commandName)
.And.HaveStdOutContaining("blazorwasm");
}

[Fact]
public void CanInstallToPathWithAt()
{
string path = Path.Combine(Path.GetTempPath(), "repro@4");
try
{
Directory.CreateDirectory(path);
new DotnetCommand(_log, "new", "console", "-o", path, "-n", "myconsole").Execute().Should().Pass();
new DotnetCommand(_log, "add", "package", "--project", Path.Combine(path, "myconsole.csproj"), "Microsoft.Azure.Functions.Worker.ProjectTemplates", "-v", "4.0.5086", "--package-directory", path).Execute().Should().Pass();
new DotnetCommand(_log, "new", "install", Path.Combine(path, "microsoft.azure.functions.worker.projecttemplates/4.0.5086/microsoft.azure.functions.worker.projecttemplates.4.0.5086.nupkg")).Execute().Should().Pass();
}
finally
{
Directory.Delete(path, recursive: true);
}
}

[Fact]
public void CanInstallRemoteNuGetPackage_LatestVariations()
{
Expand Down