Repository: dotnet/aspnetcore
File: src/ProjectTemplates/Shared/Project.cs (C#)

Code before:
        {
            argString += $" --no-https";
        }

        if (args != null)
        {
            foreach (var arg in args)
            {
                argString += " " + arg;
            }
        }

        // Save a copy of the arguments used for better diagnostic error messages later.
        // We omit the hive argument and the template output dir as they are not relevant and add noise.
        ProjectArguments = argString.Replace(hiveArg, "");

        if (!string.IsNullOrEmpty(ProjectName))
        {
            argString += $" -n \"{ProjectName}\"";
        }

        argString += $" -o {TemplateOutputDir}";

        if (Directory.Exists(TemplateOutputDir))
        {
            Output.WriteLine($"Template directory already exists, deleting contents of {TemplateOutputDir}");
            Directory.Delete(TemplateOutputDir, recursive: true);
        }

        using var createExecution = ProcessEx.Run(Output, AppContext.BaseDirectory, DotNetMuxer.MuxerPathOrDefault(), argString, environmentVariables);
        await createExecution.Exited;

        var createResult = new ProcessResult(createExecution);
        Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("create", this, createResult));

        if (!isItemTemplate)
        {
            argString = "restore /bl";
            using var restoreExecution = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), argString, environmentVariables);
            await restoreExecution.Exited;

            var restoreResult = new ProcessResult(restoreExecution);

            // Because dotnet new automatically restores but silently ignores restore errors, need to handle restore errors explicitly
            if (errorOnRestoreError && (restoreExecution.Output.Contains("Restore failed.") || restoreExecution.Error.Contains("Restore failed.")))
            {
                restoreResult.ExitCode = -1;
            }

            CaptureBinLogOnFailure(restoreExecution);


Review comment (bug):
@copilot this is causing failures for tests where the args passed already includes `-n` or `--name`. Make sure this is only set if args doesn't already setting the name.

Code after:
        {
            argString += $" --use-local-db";
        }

        if (noHttps)
        {
            argString += $" --no-https";
        }

        if (args != null)
        {
            foreach (var arg in args)
            {
                argString += " " + arg;
            }
        }

        // Save a copy of the arguments used for better diagnostic error messages later.
        // We omit the hive argument and the template output dir as they are not relevant and add noise.
        ProjectArguments = argString.Replace(hiveArg, "");

        // Only add -n parameter if ProjectName is set and args doesn't already contain -n or --name
        if (!string.IsNullOrEmpty(ProjectName) &&
            args?.Any(a => a.Contains("-n ") || a.Contains("--name ") || a == "-n" || a == "--name") != true)
        {
            argString += $" -n \"{ProjectName}\"";
        }

        argString += $" -o {TemplateOutputDir}";

        if (Directory.Exists(TemplateOutputDir))
        {
            Output.WriteLine($"Template directory already exists, deleting contents of {TemplateOutputDir}");
            Directory.Delete(TemplateOutputDir, recursive: true);
        }

        using var createExecution = ProcessEx.Run(Output, AppContext.BaseDirectory, DotNetMuxer.MuxerPathOrDefault(), argString, environmentVariables);
        await createExecution.Exited;

        var createResult = new ProcessResult(createExecution);
        Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("create", this, createResult));

        if (!isItemTemplate)
        {
            argString = "restore /bl";
            using var restoreExecution = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), argString, environmentVariables);
            await restoreExecution.Exited;

            var restoreResult = new ProcessResult(restoreExecution);

            // Because dotnet new automatically restores but silently ignores restore errors, need to handle restore errors explicitly