ModernRonin / ProjectRenamer

Conveniently rename your csproj files
Other
155 stars 14 forks source link

Failing on Path with Whitespace #19

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hey there!

I saw you said you'd fixed this issue in 2.1.1, but I don't believe it's fixed based on the error I'm seeing:

Analyzing references in your projects - depending on the number of projects this can take a bit...
Unrecognized command or argument '(Griffis)\source\repos\DataWarehouse\AzureFunctions\func-inboundparsecsvs-centralus-prod\func-inboundparsecsvs-centralus-prod\func-inboundparsecsvs-centralus-prod.csproj'
call 'dotnet list C:\Users\Elliott (Griffis)\source\repos\DataWarehouse\AzureFunctions\func-inboundparsecsvs-centralus-prod\func-inboundparsecsvs-centralus-prod\func-inboundparsecsvs-centralus-prod.csproj reference' failed - aborting
...running git reset to undo any changes...

Unfortunately, my user folder has a space in it, and it looks like the path is not quoted in the call to dotnet list.

Thanks!

ghost commented 3 years ago

Looks like it's happening somewhere around here in the Run function...

void projectReferenceCommand(string command, string project, string reference) =>
                DotNet($"{command} {project.Escape()} reference {reference.Escape()}");

            (string[] dependents, string[] dependencies) analyzeReferences()
            {
                Log(
                    "Analyzing references in your projects - depending on the number of projects this can take a bit...");

                return (
                    allProjects().Where(doesNotEqualOldProjectPath).Where(hasReferenceToOldProject).ToArray(),
                    getReferencedProjects(oldProjectPath).ToArray());

                bool hasReferenceToOldProject(string p) =>
                    getReferencedProjects(p).Any(doesEqualOldProjectPath);
            }

            bool doesNotEqualOldProjectPath(string what) => !doesEqualOldProjectPath(what);
            bool doesEqualOldProjectPath(string what) => arePathsEqual(what, oldProjectPath);

            IEnumerable<string> getReferencedProjects(string project)
            {
                var baseDirectory = Path.GetFullPath(Path.GetDirectoryName(project));
                var relativeReferences = DotNetRead($"list {project} reference")
                    .Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries)
                    .Skip(2);
                return relativeReferences.Select(r => r.ToAbsolutePath(baseDirectory));
            }
ModernRonin commented 3 years ago

thanks for finding! a new version is out :-)

ghost commented 3 years ago

Glad it was a one-liner! Thanks!