From 531a4627d6e829eff66ceefa702dfe32439b4748 Mon Sep 17 00:00:00 2001 From: flavio Date: Fri, 23 Sep 2022 23:15:13 -0300 Subject: [PATCH] add suport for .vbproj file extension project --- ModernRonin.ProjectRenamer/Application.cs | 4 ++-- ModernRonin.ProjectRenamer/Configuration.cs | 1 + ModernRonin.ProjectRenamer/ConfigurationSetup.cs | 16 +++++++++++----- ModernRonin.ProjectRenamer/Filesystem.cs | 4 ++-- ModernRonin.ProjectRenamer/IFilesystem.cs | 2 +- .../Properties/launchSettings.json | 5 +++++ 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/ModernRonin.ProjectRenamer/Application.cs b/ModernRonin.ProjectRenamer/Application.cs index d3642ef..1212cd2 100644 --- a/ModernRonin.ProjectRenamer/Application.cs +++ b/ModernRonin.ProjectRenamer/Application.cs @@ -53,7 +53,7 @@ public void Run() : Path.GetDirectoryName(oldDir); var newDir = _configuration.NewProjectName.ToAbsolutePath(newBase); var newFileName = Path.GetFileName(_configuration.NewProjectName); - var newProjectPath = Path.Combine(newDir, $"{newFileName}{Constants.ProjectFileExtension}"); + var newProjectPath = Path.Combine(newDir, $"{newFileName}{_configuration.ProjectFileExtension}"); var isPaketUsed = _filesystem.DoesDirectoryExist(".paket"); var gitVersion = _git.GetVersion(); if (!_configuration.DontReviewSettings) @@ -231,7 +231,7 @@ string[] allProjects() return all.Except(excluded).ToArray(); - string[] filesIn(string directory) => _filesystem.FindProjectFiles(directory, true); + string[] filesIn(string directory) => _filesystem.FindProjectFiles(directory, true, _configuration.ProjectFileExtension); } } diff --git a/ModernRonin.ProjectRenamer/Configuration.cs b/ModernRonin.ProjectRenamer/Configuration.cs index 896f4ce..abdeb8f 100644 --- a/ModernRonin.ProjectRenamer/Configuration.cs +++ b/ModernRonin.ProjectRenamer/Configuration.cs @@ -9,5 +9,6 @@ public class Configuration public string ExcludedDirectory { get; set; } = string.Empty; public string NewProjectName { get; set; } public string OldProjectName { get; set; } + public string ProjectFileExtension { get; set; } = Constants.ProjectFileExtension; } } \ No newline at end of file diff --git a/ModernRonin.ProjectRenamer/ConfigurationSetup.cs b/ModernRonin.ProjectRenamer/ConfigurationSetup.cs index 19d6ed6..1c0bfb5 100644 --- a/ModernRonin.ProjectRenamer/ConfigurationSetup.cs +++ b/ModernRonin.ProjectRenamer/ConfigurationSetup.cs @@ -44,8 +44,8 @@ public ConfigurationSetup(ILogger console, $"Do not specify paths for input/'old' project names, please.{Environment.NewLine}{Environment.NewLine}{helpOverview}"); } - configuration.OldProjectName = RemoveProjectFileExtension(configuration.OldProjectName); - configuration.NewProjectName = RemoveProjectFileExtension(configuration.NewProjectName); + configuration.OldProjectName = RemoveProjectFileExtension(configuration.OldProjectName, configuration.ProjectFileExtension); + configuration.NewProjectName = RemoveProjectFileExtension(configuration.NewProjectName, configuration.ProjectFileExtension); return (configuration, solutionPath); default: @@ -97,12 +97,18 @@ public ConfigurationSetup(ILogger console, .WithShortName("e") .WithHelp( "exclude this directory from project reference updates; must be a relative path to the current directory"); + cfg.Parameter(c => c.ProjectFileExtension) + .MakeOptional() + .WithLongName("project-extension") + .WithShortName("pe") + .ExpectAt(3) + .WithHelp("the file extension for the project, ex: .csproj, .vbproj"); return (parser.HelpOverview, parser.Parse(args)); } - static string RemoveProjectFileExtension(string projectName) => - projectName.EndsWith(Constants.ProjectFileExtension, StringComparison.InvariantCultureIgnoreCase) - ? projectName[..^Constants.ProjectFileExtension.Length] + static string RemoveProjectFileExtension(string projectName, string projectFileExtension) => + projectName.EndsWith(projectFileExtension, StringComparison.InvariantCultureIgnoreCase) + ? projectName[..^projectFileExtension.Length] : projectName; } } \ No newline at end of file diff --git a/ModernRonin.ProjectRenamer/Filesystem.cs b/ModernRonin.ProjectRenamer/Filesystem.cs index c4f1bf8..aa4c8c4 100644 --- a/ModernRonin.ProjectRenamer/Filesystem.cs +++ b/ModernRonin.ProjectRenamer/Filesystem.cs @@ -9,9 +9,9 @@ public class Filesystem : IFilesystem public bool DoesDirectoryExist(string directory) => Directory.Exists(directory); public void EnsureDirectoryExists(string directory) => Directory.CreateDirectory(directory); - public string[] FindProjectFiles(string directory, bool doRecurse) => + public string[] FindProjectFiles(string directory, bool doRecurse, string projectFileExtension) => Directory - .EnumerateFiles(directory, $"*{Constants.ProjectFileExtension}", SearchOption(doRecurse)) + .EnumerateFiles(directory, $"*{projectFileExtension}", SearchOption(doRecurse)) .ToArray(); public string[] FindSolutionFiles(string directory, bool doRecurse) => diff --git a/ModernRonin.ProjectRenamer/IFilesystem.cs b/ModernRonin.ProjectRenamer/IFilesystem.cs index f1d9445..c9f8f0d 100644 --- a/ModernRonin.ProjectRenamer/IFilesystem.cs +++ b/ModernRonin.ProjectRenamer/IFilesystem.cs @@ -5,7 +5,7 @@ public interface IFilesystem string CurrentDirectory { get; } bool DoesDirectoryExist(string directory); void EnsureDirectoryExists(string directory); - string[] FindProjectFiles(string directory, bool doRecurse); + string[] FindProjectFiles(string directory, bool doRecurse, string projectFileExtension); string[] FindSolutionFiles(string directory, bool doRecurse); } } \ No newline at end of file diff --git a/ModernRonin.ProjectRenamer/Properties/launchSettings.json b/ModernRonin.ProjectRenamer/Properties/launchSettings.json index f28315b..77b963a 100644 --- a/ModernRonin.ProjectRenamer/Properties/launchSettings.json +++ b/ModernRonin.ProjectRenamer/Properties/launchSettings.json @@ -5,6 +5,11 @@ "commandLineArgs": "LibraryInSolutionFolder ProjectInSolutionFolder", "workingDirectory": "C:\\Projects\\Github\\ProjectRenamerTestBed" }, + "rename library to project, in solution folder, .vbproj": { + "commandName": "Project", + "commandLineArgs": "LibraryInSolutionFolder ProjectInSolutionFolder --project-extension=.vbproj", + "workingDirectory": "C:\\Projects\\Github\\ProjectRenamerTestBed" + }, "rename project to library, in solution folder, no review": { "commandName": "Project", "commandLineArgs": "ProjectInSolutionFolder LibraryInSolutionFolder --no-review",