diff --git a/SlnAndCsprojParityChecker.sln b/SlnAndCsprojParityChecker.sln index 2ff1af6..586219f 100644 --- a/SlnAndCsprojParityChecker.sln +++ b/SlnAndCsprojParityChecker.sln @@ -1,6 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnAndCsprojParityChecker", "SlnAndCsprojParityChecker\SlnAndCsprojParityChecker.csproj", "{0EAC3CFF-28B2-4ACA-BC18-8148A75F89D9}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SolutionParityChecker.CLI", "SolutionParityChecker.CLI\SolutionParityChecker.CLI.csproj", "{0EAC3CFF-28B2-4ACA-BC18-8148A75F89D9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SolutionParityChecker", "SolutionParityChecker\SolutionParityChecker.csproj", "{2635CBAC-0CEF-4BEE-A6FD-154796A4F467}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -12,5 +14,9 @@ Global {0EAC3CFF-28B2-4ACA-BC18-8148A75F89D9}.Debug|Any CPU.Build.0 = Debug|Any CPU {0EAC3CFF-28B2-4ACA-BC18-8148A75F89D9}.Release|Any CPU.ActiveCfg = Release|Any CPU {0EAC3CFF-28B2-4ACA-BC18-8148A75F89D9}.Release|Any CPU.Build.0 = Release|Any CPU + {2635CBAC-0CEF-4BEE-A6FD-154796A4F467}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2635CBAC-0CEF-4BEE-A6FD-154796A4F467}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2635CBAC-0CEF-4BEE-A6FD-154796A4F467}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2635CBAC-0CEF-4BEE-A6FD-154796A4F467}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/SlnAndCsprojParityChecker/Commands/CompareCommand.cs b/SolutionParityChecker.CLI/Commands/CompareCommand.cs similarity index 65% rename from SlnAndCsprojParityChecker/Commands/CompareCommand.cs rename to SolutionParityChecker.CLI/Commands/CompareCommand.cs index eae69c2..ef9c917 100644 --- a/SlnAndCsprojParityChecker/Commands/CompareCommand.cs +++ b/SolutionParityChecker.CLI/Commands/CompareCommand.cs @@ -3,7 +3,7 @@ using Microsoft.Build.Construction; using Spectre.Console; using Spectre.Console.Cli; -namespace SlnAndCsprojParityChecker.Commands; +namespace SolutionParityChecker.CLI.Commands; public class CompareCommand : Command { @@ -13,7 +13,7 @@ public class CompareCommand : Command public required string SolutionFolderPath { get; set; } [CommandArgument(1, "")] - public required string SolutionFilePath{ get; set; } + public required string SolutionFilePath { get; set; } [CommandOption("-l|--logprojectfiles")] [Description("true to enable logging of all project files. Default is false.")] @@ -27,8 +27,9 @@ public class CompareCommand : Command var pathToSolutionFile = settings.SolutionFilePath; Console.WriteLine($"Retrieving C# Projects from {folderDirectory}"); - var csprojList = Directory.GetFiles(folderDirectory, "*.csproj", SearchOption.AllDirectories); - csprojList = csprojList.Select(x => x.Replace(folderDirectory, "")).ToArray(); + var csprojList = SolutionParityChecker.RetrieveAllCSharpProjectNamesFromFolder( + folderDirectory + ); if (settings.LogAllProjectFileNames) { @@ -43,29 +44,25 @@ public class CompareCommand : Command Console.WriteLine($"Parsing Solution File: {pathToSolutionFile}"); // Load the solution file - var solutionFile = SolutionFile.Parse(pathToSolutionFile); + var solutionFile = SolutionParityChecker.ParseSolutionFileFromPath(pathToSolutionFile); if (solutionFile == null) { - Console.WriteLine("Failed to parse solution file. The file was either not found or malformed."); + Console.WriteLine( + "Failed to parse solution file. The file was either not found or malformed." + ); return 1; } // Get the list of projects - var projects = solutionFile.ProjectsInOrder; - var projectsMissingFromSolution = new List(); - - foreach (var project in csprojList) - { - var projectInSolution = projects.FirstOrDefault(x => x.RelativePath == project); - - if (projectInSolution == null) - { - projectsMissingFromSolution.Add(project); - } - } + var projectsMissingFromSolution = SolutionParityChecker.FindProjectsMissingFromSolution( + csprojList, + solutionFile + ); Console.WriteLine("=================================================="); - Console.WriteLine($"Missing {projectsMissingFromSolution.Count} C# Projects from Solution File"); + Console.WriteLine( + $"Missing {projectsMissingFromSolution.Count} C# Projects from Solution File" + ); foreach (var project in projectsMissingFromSolution) { @@ -75,4 +72,4 @@ public class CompareCommand : Command Console.WriteLine("Done!"); return 0; } -} \ No newline at end of file +} diff --git a/SlnAndCsprojParityChecker/Program.cs b/SolutionParityChecker.CLI/Program.cs similarity index 65% rename from SlnAndCsprojParityChecker/Program.cs rename to SolutionParityChecker.CLI/Program.cs index 1d7448c..d1ed55b 100644 --- a/SlnAndCsprojParityChecker/Program.cs +++ b/SolutionParityChecker.CLI/Program.cs @@ -1,10 +1,10 @@ -using SlnAndCsprojParityChecker.Commands; +using SolutionParityChecker.CLI.Commands; using Spectre.Console.Cli; var app = new CommandApp(); app.Configure(config => { - config.SetApplicationName("SlnAndCsprojParityChecker"); + config.SetApplicationName("SolutionParityChecker"); config.ValidateExamples(); config.AddCommand("compare"); diff --git a/SlnAndCsprojParityChecker/SlnAndCsprojParityChecker.csproj b/SolutionParityChecker.CLI/SolutionParityChecker.CLI.csproj similarity index 80% rename from SlnAndCsprojParityChecker/SlnAndCsprojParityChecker.csproj rename to SolutionParityChecker.CLI/SolutionParityChecker.CLI.csproj index d1a6e75..d5da327 100644 --- a/SlnAndCsprojParityChecker/SlnAndCsprojParityChecker.csproj +++ b/SolutionParityChecker.CLI/SolutionParityChecker.CLI.csproj @@ -14,4 +14,8 @@ + + + + diff --git a/SolutionParityChecker/SolutionParityChecker.cs b/SolutionParityChecker/SolutionParityChecker.cs new file mode 100644 index 0000000..2812b75 --- /dev/null +++ b/SolutionParityChecker/SolutionParityChecker.cs @@ -0,0 +1,50 @@ +using Microsoft.Build.Construction; + +namespace SolutionParityChecker; + +public static class SolutionParityChecker +{ + public static void CompareSolutionAndCSharpProjects( + string solutionFolderPath, + string solutionFilePath + ) { } + + public static string[] RetrieveAllCSharpProjectNamesFromFolder(string solutionFolderPath) + { + var csprojList = Directory.GetFiles( + solutionFolderPath, + "*.csproj", + SearchOption.AllDirectories + ); + csprojList = csprojList.Select(x => x.Replace(solutionFolderPath, "")).ToArray(); + return csprojList; + } + + public static SolutionFile? ParseSolutionFileFromPath(string solutionFilePath) + { + var solutionFile = SolutionFile.Parse(solutionFilePath); + + return solutionFile; + } + + public static List FindProjectsMissingFromSolution( + string[] csprojList, + SolutionFile solutionFile + ) + { + var projects = solutionFile.ProjectsInOrder; + var projectsMissingFromSolution = new List(); + + foreach (var project in csprojList) + { + var projectInSolution = projects.FirstOrDefault(x => x.RelativePath == project); + + if (projectInSolution == null) + { + projectsMissingFromSolution.Add(project); + } + } + + return projectsMissingFromSolution; + } +} diff --git a/SolutionParityChecker/SolutionParityChecker.csproj b/SolutionParityChecker/SolutionParityChecker.csproj new file mode 100644 index 0000000..af68004 --- /dev/null +++ b/SolutionParityChecker/SolutionParityChecker.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + +