From 1764142382ec6fc2b222eb88a8edbcbddcdfe465 Mon Sep 17 00:00:00 2001 From: Matthew Parker Date: Thu, 31 Aug 2023 21:15:49 +1000 Subject: [PATCH] README.md --- README.md | 25 ++++++- SlnAndCsprojParityChecker.sln | 8 ++ .../Commands/CompareCommand.cs | 4 +- .../Commands/FormatCsprojCommand.cs | 75 ++++++++++++++++--- .../SolutionParityChecker.cs | 10 ++- 5 files changed, 108 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ef629c9..e5e53ee 100644 --- a/README.md +++ b/README.md @@ -1 +1,24 @@ -# SlnAndCsprojParityChecker \ No newline at end of file +# Solution Parity Checker + +Various tools to manage a C# solution. + +## CLI + +**compare** `` `` +_options_ +`-l --logprojectfiles` logs all project files found in folder + +implicit-usings `` +_options_ +`-m|--add-missing` adds missing implicit usings to all project files +`-d|--enable-disabled` enables disabled implicit usings in all project files +`-a|--enable-all` enables implicit usings in all project files + +**format-csproj** +`--folder ` or +`--sln ` or +`--project ` + +## App + +TODO \ No newline at end of file diff --git a/SlnAndCsprojParityChecker.sln b/SlnAndCsprojParityChecker.sln index 6ad3fc2..491b96c 100644 --- a/SlnAndCsprojParityChecker.sln +++ b/SlnAndCsprojParityChecker.sln @@ -6,6 +6,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SolutionParityChecker", "So EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SolutionParityChecker.App", "SolutionParityChecker.App\SolutionParityChecker.App.csproj", "{A7F46873-C8EC-4C2E-86F5-B9F2472C8036}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4B49F43F-2B01-487B-9831-6CF51AE4A977}" + ProjectSection(SolutionItems) = preProject + .csharpierrc = .csharpierrc + .gitignore = .gitignore + global.json = global.json + README.md = README.md + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/SolutionParityChecker.CLI/Commands/CompareCommand.cs b/SolutionParityChecker.CLI/Commands/CompareCommand.cs index ef9c917..2d795d4 100644 --- a/SolutionParityChecker.CLI/Commands/CompareCommand.cs +++ b/SolutionParityChecker.CLI/Commands/CompareCommand.cs @@ -16,7 +16,9 @@ public class CompareCommand : Command public required string SolutionFilePath { get; set; } [CommandOption("-l|--logprojectfiles")] - [Description("true to enable logging of all project files. Default is false.")] + [Description( + "true to enable log output of all project files found in folder. Default is false." + )] [DefaultValue(false)] public bool LogAllProjectFileNames { get; set; } = false; } diff --git a/SolutionParityChecker.CLI/Commands/FormatCsprojCommand.cs b/SolutionParityChecker.CLI/Commands/FormatCsprojCommand.cs index 836aa7d..4a96c0b 100644 --- a/SolutionParityChecker.CLI/Commands/FormatCsprojCommand.cs +++ b/SolutionParityChecker.CLI/Commands/FormatCsprojCommand.cs @@ -7,20 +7,73 @@ public class FormatCsprojCommand : Command { public sealed class Settings : CommandSettings { - [CommandArgument(1, "")] - public required string CsprojFilePath { get; set; } - - [CommandOption("-a|--enable-all")] - [Description("true to enable logging of all project files. Default is false.")] - [DefaultValue(false)] - public bool EnableAll { get; set; } = false; + [CommandOption("--project ")] + public string? CsprojFilePath { get; set; } + + [CommandOption("--folder ")] + public string? SolutionFolderPath { get; set; } + + [CommandOption("--sln ")] + public string? SolutionFilePath { get; set; } } public override int Execute(CommandContext context, Settings settings) { - var pathToCsprojFile = settings.CsprojFilePath; - Console.WriteLine($"Retrieving C# Project from {pathToCsprojFile}"); - FormatCsproj.FormatCsprojFile(pathToCsprojFile); - return 0; + if (!string.IsNullOrWhiteSpace(settings.CsprojFilePath)) + { + var pathToCsprojFile = settings.CsprojFilePath; + Console.WriteLine($"Retrieving C# Project from {pathToCsprojFile}"); + FormatCsproj.FormatCsprojFile(pathToCsprojFile); + Console.WriteLine("Done!"); + return 0; + } + else if (!string.IsNullOrWhiteSpace(settings.SolutionFilePath)) + { + var test = SolutionParityChecker.ParseSolutionFileFromPath(settings.SolutionFilePath); + if (test == null) + { + Console.WriteLine( + "Failed to parse solution file. The file was either not found or malformed." + ); + return 1; + } + var cSharpProjects = SolutionParityChecker.GetCSharpProjectObjectsFromSolutionFile( + test + ); + Console.WriteLine($"Found {cSharpProjects.Count} C# Projects"); + Console.WriteLine("=================================================="); + foreach (var project in cSharpProjects) + { + FormatCsproj.FormatCsprojFile(project.FullPath); + } + Console.WriteLine("Done!"); + return 0; + } + else if (!string.IsNullOrWhiteSpace(settings.SolutionFolderPath)) + { + var folderDirectory = settings.SolutionFolderPath; // Include the trailing slash + Console.WriteLine($"Retrieving C# Projects from {folderDirectory}"); + + var csprojList = SolutionParityChecker.RetrieveAllCSharpProjectFullPathsFromFolder( + folderDirectory + ); + + Console.WriteLine($"Retrieved {csprojList.Length} C# Projects"); + Console.WriteLine("=================================================="); + + foreach (var project in csprojList) + { + FormatCsproj.FormatCsprojFile(project); + } + Console.WriteLine("Done!"); + return 0; + } + else + { + Console.WriteLine( + "No arguments were provided. Please provide a csproj, folder, or solution file." + ); + return 1; + } } } diff --git a/SolutionParityChecker/SolutionParityChecker.cs b/SolutionParityChecker/SolutionParityChecker.cs index c71f4f2..9e57f19 100644 --- a/SolutionParityChecker/SolutionParityChecker.cs +++ b/SolutionParityChecker/SolutionParityChecker.cs @@ -18,6 +18,14 @@ public static class SolutionParityChecker } public static string[] RetrieveAllCSharpProjectNamesFromFolder(string solutionFolderPath) + { + var csprojList = RetrieveAllCSharpProjectFullPathsFromFolder(solutionFolderPath); + + csprojList = csprojList.Select(x => x.Replace(solutionFolderPath, "")).ToArray(); + return csprojList; + } + + public static string[] RetrieveAllCSharpProjectFullPathsFromFolder(string solutionFolderPath) { // if solutionFolderPath does not end with a slash, add one if (solutionFolderPath[^1] != Path.DirectorySeparatorChar) @@ -29,7 +37,6 @@ public static class SolutionParityChecker "*.csproj", SearchOption.AllDirectories ); - csprojList = csprojList.Select(x => x.Replace(solutionFolderPath, "")).ToArray(); return csprojList; } @@ -60,6 +67,7 @@ public static class SolutionParityChecker return projectsMissingFromSolution; } + public static List GetCSharpProjectObjectsFromSolutionFile( SolutionFile solutionFile )