README.md

This commit is contained in:
Matthew Parker
2023-08-31 21:15:49 +10:00
parent 526ff1b43d
commit 1764142382
5 changed files with 108 additions and 14 deletions

View File

@@ -1 +1,24 @@
# SlnAndCsprojParityChecker # Solution Parity Checker
Various tools to manage a C# solution.
## CLI
**compare** `<SolutionFolderPath>` `<SolutionFilePath>`
_options_
`-l --logprojectfiles` logs all project files found in folder
implicit-usings `<SolutionFilePath>`
_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 <SolutionFolderPath>` or
`--sln <SolutionFilePath>` or
`--project <CsprojFilePath>`
## App
TODO

View File

@@ -6,6 +6,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SolutionParityChecker", "So
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SolutionParityChecker.App", "SolutionParityChecker.App\SolutionParityChecker.App.csproj", "{A7F46873-C8EC-4C2E-86F5-B9F2472C8036}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SolutionParityChecker.App", "SolutionParityChecker.App\SolutionParityChecker.App.csproj", "{A7F46873-C8EC-4C2E-86F5-B9F2472C8036}"
EndProject 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 Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU

View File

@@ -16,7 +16,9 @@ public class CompareCommand : Command<CompareCommand.Settings>
public required string SolutionFilePath { get; set; } public required string SolutionFilePath { get; set; }
[CommandOption("-l|--logprojectfiles")] [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)] [DefaultValue(false)]
public bool LogAllProjectFileNames { get; set; } = false; public bool LogAllProjectFileNames { get; set; } = false;
} }

View File

@@ -7,20 +7,73 @@ public class FormatCsprojCommand : Command<FormatCsprojCommand.Settings>
{ {
public sealed class Settings : CommandSettings public sealed class Settings : CommandSettings
{ {
[CommandArgument(1, "<CsprojFilePath>")] [CommandOption("--project <CsprojFilePath>")]
public required string CsprojFilePath { get; set; } public string? CsprojFilePath { get; set; }
[CommandOption("-a|--enable-all")] [CommandOption("--folder <SolutionFolderPath>")]
[Description("true to enable logging of all project files. Default is false.")] public string? SolutionFolderPath { get; set; }
[DefaultValue(false)]
public bool EnableAll { get; set; } = false; [CommandOption("--sln <SolutionFilePath>")]
public string? SolutionFilePath { get; set; }
} }
public override int Execute(CommandContext context, Settings settings) public override int Execute(CommandContext context, Settings settings)
{ {
var pathToCsprojFile = settings.CsprojFilePath; if (!string.IsNullOrWhiteSpace(settings.CsprojFilePath))
Console.WriteLine($"Retrieving C# Project from {pathToCsprojFile}"); {
FormatCsproj.FormatCsprojFile(pathToCsprojFile); var pathToCsprojFile = settings.CsprojFilePath;
return 0; 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;
}
} }
} }

View File

@@ -18,6 +18,14 @@ public static class SolutionParityChecker
} }
public static string[] RetrieveAllCSharpProjectNamesFromFolder(string solutionFolderPath) 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 does not end with a slash, add one
if (solutionFolderPath[^1] != Path.DirectorySeparatorChar) if (solutionFolderPath[^1] != Path.DirectorySeparatorChar)
@@ -29,7 +37,6 @@ public static class SolutionParityChecker
"*.csproj", "*.csproj",
SearchOption.AllDirectories SearchOption.AllDirectories
); );
csprojList = csprojList.Select(x => x.Replace(solutionFolderPath, "")).ToArray();
return csprojList; return csprojList;
} }
@@ -60,6 +67,7 @@ public static class SolutionParityChecker
return projectsMissingFromSolution; return projectsMissingFromSolution;
} }
public static List<ProjectRootElement> GetCSharpProjectObjectsFromSolutionFile( public static List<ProjectRootElement> GetCSharpProjectObjectsFromSolutionFile(
SolutionFile solutionFile SolutionFile solutionFile
) )