From 99bb96a8d648a1f83405d3485c00611e7bd01f03 Mon Sep 17 00:00:00 2001 From: Mark Hajek Date: Sun, 13 Dec 2020 14:05:16 +0000 Subject: [PATCH 1/2] fixes #16 --- ModernRonin.ProjectRenamer/Application.cs | 14 ++++++++++---- ModernRonin.ProjectRenamer/CommonExtensions.cs | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ModernRonin.ProjectRenamer/Application.cs b/ModernRonin.ProjectRenamer/Application.cs index 850f0f0..c13efd1 100644 --- a/ModernRonin.ProjectRenamer/Application.cs +++ b/ModernRonin.ProjectRenamer/Application.cs @@ -76,7 +76,7 @@ void addNewReferences() dependencies.ForEach(d => addReference(newProjectPath, d)); void addReference(string project, string reference) => - DotNet($"add {project} reference {reference}"); + projectReferenceCommand("add", project, reference); } void removeOldReferences() @@ -85,9 +85,12 @@ void removeOldReferences() dependencies.ForEach(d => removeReference(oldProjectPath, d)); void removeReference(string project, string reference) => - DotNet($"remove {project} reference {reference}"); + projectReferenceCommand("remove", project, reference); } + void projectReferenceCommand(string command, string project, string reference) => + DotNet($"{command} {project.Escape()} reference {reference.Escape()}"); + (string[] dependents, string[] dependencies) analyzeReferences() { Log( @@ -188,10 +191,13 @@ void addToSolution() var solutionFolderArgument = string.IsNullOrWhiteSpace(solutionFolderPath) ? string.Empty : $"-s \"{solutionFolderPath}\""; - DotNet($"sln add {solutionFolderArgument} {newProjectPath}"); + solutionCommand($"add {solutionFolderArgument}", newProjectPath); } - void removeFromSolution() => DotNet($"sln remove {oldProjectPath}"); + void removeFromSolution() => solutionCommand("remove", oldProjectPath); + + void solutionCommand(string command, string projectPath) => + DotNet($"sln {command} {projectPath.Escape()}"); (bool wasFound, string projectPath, string solutionFolder) findProject() { diff --git a/ModernRonin.ProjectRenamer/CommonExtensions.cs b/ModernRonin.ProjectRenamer/CommonExtensions.cs index 058089a..fe45b21 100644 --- a/ModernRonin.ProjectRenamer/CommonExtensions.cs +++ b/ModernRonin.ProjectRenamer/CommonExtensions.cs @@ -7,6 +7,8 @@ public static class CommonExtensions { public static string AsText(this bool self) => self ? "yes" : "no"; + public static string Escape(this string self) => $"\"{self}\""; + public static bool IsDirectorySeparator(this char self) => self == Path.DirectorySeparatorChar || self == Path.AltDirectorySeparatorChar; From 774fc9cfb8e3929f8429501bb0a757bd72f72928 Mon Sep 17 00:00:00 2001 From: Mark Hajek Date: Sun, 13 Dec 2020 14:07:33 +0000 Subject: [PATCH 2/2] updated release-history --- ModernRonin.ProjectRenamer/release.history | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ModernRonin.ProjectRenamer/release.history b/ModernRonin.ProjectRenamer/release.history index 2f720d3..5e3fa76 100644 --- a/ModernRonin.ProjectRenamer/release.history +++ b/ModernRonin.ProjectRenamer/release.history @@ -1,7 +1,9 @@  - 2.1.0 + 2.1.1 +2.1.1: +* bugfix: projects in paths containing whitespace no longer crash the dotnet commands; thanks to @NicolasRiou for reporting the bug 2.1.0: * feature: you can move projects to different folders now instead of just renaming them * feature: you can specify a directory to exclude from project reference updates