diff --git a/src/CommandLine/Commands/SlnListCommand.cs b/src/CommandLine/Commands/SlnListCommand.cs deleted file mode 100644 index 0a662231c2..0000000000 --- a/src/CommandLine/Commands/SlnListCommand.cs +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) Josef Pihrt and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.MSBuild; -using static Roslynator.Logger; - -namespace Roslynator.CommandLine; - -internal class SlnListCommand : MSBuildWorkspaceCommand -{ - public SlnListCommand(SlnListCommandLineOptions options, in ProjectFilter projectFilter, FileSystemFilter fileSystemFilter) : base(projectFilter, fileSystemFilter) - { - Options = options; - } - - public SlnListCommandLineOptions Options { get; } - - public override Task ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) - { - return Task.FromResult(CommandResults.Success); - } - - protected override async Task ExecuteAsync( - string path, - MSBuildWorkspace workspace, - IProgress progress = null, - CancellationToken cancellationToken = default) - { - if (!string.Equals(Path.GetExtension(path), ".sln", StringComparison.OrdinalIgnoreCase)) - { - WriteLine($"File is not a solution file: '{path}'.", Verbosity.Quiet); - return CommandResults.Fail; - } - - workspace.LoadMetadataForReferencedProjects = true; - - var consoleProgress = new ConsoleProgressReporter(shouldSaveProgress: true); - - var loader = new MSBuildProjectLoader(workspace); - - WriteLine($"Load solution '{path}'", Verbosity.Minimal); - - SolutionInfo solutionInfo = await loader.LoadSolutionInfoAsync(path, consoleProgress, cancellationToken: cancellationToken); - - string solutionDirectory = Path.GetDirectoryName(solutionInfo.FilePath); - - Dictionary> projectInfos = solutionInfo.Projects - .GroupBy(f => f.FilePath) - .ToDictionary(f => f.Key, f => f.ToImmutableArray()); - - Dictionary> projects = consoleProgress.Projects; - - int nameMaxLength = projects.Max(f => Path.GetFileNameWithoutExtension(f.Key).Length); - - int targetFrameworksMaxLength = projects.Max(f => - { - List frameworks = f.Value; - - return (frameworks is not null) ? $"({string.Join(", ", frameworks)})".Length : 0; - }); - - bool anyHasTargetFrameworks = projects.Any(f => f.Value is not null); - - WriteLine(); - WriteLine($"{projects.Count} {((projects.Count == 1) ? "project" : "projects")} found in solution '{Path.GetFileNameWithoutExtension(solutionInfo.FilePath)}' [{solutionInfo.FilePath}]", ConsoleColors.Green, Verbosity.Minimal); - - foreach (KeyValuePair> kvp in projects - .OrderBy(f => Path.GetFileName(f.Key))) - { - string projectPath = kvp.Key; - List targetFrameworks = kvp.Value; - - ProjectInfo projectInfo = projectInfos[projectPath][0]; - - string projectName = Path.GetFileNameWithoutExtension(projectPath); - - Write($" {projectName.PadRight(nameMaxLength)} {projectInfo.Language}", Verbosity.Normal); - - if (anyHasTargetFrameworks) - Write(" ", Verbosity.Normal); - - if (targetFrameworks is not null) - { - string targetFrameworksText = $"({string.Join(", ", targetFrameworks.OrderBy(f => f))})"; - Write(targetFrameworksText.PadRight(targetFrameworksMaxLength), Verbosity.Normal); - } - else - { - Write(new string(' ', targetFrameworksMaxLength), Verbosity.Normal); - } - - WriteLine($" [{PathUtilities.TrimStart(projectPath, solutionDirectory)}]", Verbosity.Normal); - } - - WriteLine(); - - return CommandResults.Success; - } -} diff --git a/src/CommandLine/Options/SlnListCommandLineOptions.cs b/src/CommandLine/Options/SlnListCommandLineOptions.cs deleted file mode 100644 index 39fdf6fc49..0000000000 --- a/src/CommandLine/Options/SlnListCommandLineOptions.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Josef Pihrt and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Collections.Generic; -using CommandLine; - -namespace Roslynator.CommandLine; - -#if DEBUG -[Verb("sln-list", HelpText = "Gets an information about specified solution and its projects.")] -#endif -public class SlnListCommandLineOptions : MSBuildCommandLineOptions -{ - [Value( - index: 0, - HelpText = "Path to one or more project/solution files.", - MetaName = "")] - public IEnumerable Paths { get; set; } -} diff --git a/src/CommandLine/Program.cs b/src/CommandLine/Program.cs index f3bb92a11f..ad03a888d7 100644 --- a/src/CommandLine/Program.cs +++ b/src/CommandLine/Program.cs @@ -110,7 +110,6 @@ private static int Main(string[] args) typeof(SpellcheckCommandLineOptions), #if DEBUG typeof(FindSymbolsCommandLineOptions), - typeof(ListVisualStudioCommandLineOptions), typeof(SlnListCommandLineOptions), #endif }); @@ -200,8 +199,6 @@ private static int Main(string[] args) #if DEBUG case FindSymbolsCommandLineOptions findSymbolsCommandLineOptions: return FindSymbolsAsync(findSymbolsCommandLineOptions).Result; - case SlnListCommandLineOptions slnListCommandLineOptions: - return SlnListAsync(slnListCommandLineOptions).Result; #endif default: throw new InvalidOperationException(); @@ -662,21 +659,6 @@ private static async Task SpellcheckAsync(SpellcheckCommandLineOptions opti } #if DEBUG - private static async Task SlnListAsync(SlnListCommandLineOptions options) - { - if (!options.TryGetProjectFilter(out ProjectFilter projectFilter)) - return ExitCodes.Error; - - if (!TryParsePaths(options.Paths, out ImmutableArray paths)) - return ExitCodes.Error; - - var command = new SlnListCommand(options, projectFilter, FileSystemFilter.CreateOrDefault(options.Include, options.Exclude)); - - CommandStatus status = await command.ExecuteAsync(paths, options.MSBuildPath, options.Properties); - - return GetExitCode(status); - } - private static int ListVisualStudio(ListVisualStudioCommandLineOptions options) { var command = new ListVisualStudioCommand(options);