diff --git a/ChangeLog.md b/ChangeLog.md index ee9cabbf62..4d8b20982b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix [RCS1234](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1234) ([PR](https://github.com/dotnet/roslynator/pull/1233)) - Fix refactoring [Inline method](https://josefpihrt.github.io/docs/roslynator/refactorings/RR0062) ([PR](https://github.com/dotnet/roslynator/pull/1234)) - [CLI] Fix globbing ([PR](https://github.com/dotnet/roslynator/pull/1238)) +- [CLI] Remove assembly resolving ([PR](https://github.com/dotnet/roslynator/pull/1237)) ## [4.6.1] - 2023-10-23 diff --git a/src/CommandLine/AssemblyResolver.cs b/src/CommandLine/AssemblyResolver.cs deleted file mode 100644 index e5319d5301..0000000000 --- a/src/CommandLine/AssemblyResolver.cs +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) .NET Foundation and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.Reflection; -using static Roslynator.Logger; - -namespace Roslynator.CommandLine; - -internal static class AssemblyResolver -{ - static AssemblyResolver() - { - AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => CurrentDomain_AssemblyResolve(sender, args); - } - - internal static void Register() - { - } - - [SuppressMessage("Redundancy", "RCS1163:Unused parameter.")] - private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) - { - var assemblyName = new AssemblyName(args.Name); - - if (assemblyName.Name.EndsWith(".resources")) - return null; - - WriteLine($"Resolve assembly '{args.Name}'", ConsoleColors.DarkGray, Verbosity.Diagnostic); - - switch (assemblyName.Name) - { - case "Microsoft.CodeAnalysis": - case "Microsoft.CodeAnalysis.CSharp": - case "Microsoft.CodeAnalysis.CSharp.Workspaces": - case "Microsoft.CodeAnalysis.VisualBasic": - case "Microsoft.CodeAnalysis.VisualBasic.Workspaces": - case "Microsoft.CodeAnalysis.Workspaces": - case "System.Collections.Immutable": - case "System.Composition.AttributedModel": - case "System.Composition.Convention": - case "System.Composition.Hosting": - case "System.Composition.Runtime": - case "System.Composition.TypedParts": - { - Assembly assembly = FindLoadedAssembly(); - - if (assembly is not null) - return assembly; - - break; - } - } - - WriteLine($"Unable to resolve assembly '{assemblyName}'.", ConsoleColors.DarkGray, Verbosity.Diagnostic); - - return null; - - Assembly FindLoadedAssembly() - { - Assembly result = null; - - foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) - { - AssemblyName an = assembly.GetName(); - - if (assemblyName.Name == an.Name - && assemblyName.Version <= an.Version) - { - if (result is null) - { - result = assembly; - } - else if (result.GetName().Version < an.Version) - { - result = assembly; - } - } - } - - return result; - } - } -} diff --git a/src/CommandLine/Commands/AnalyzeCommand.cs b/src/CommandLine/Commands/AnalyzeCommand.cs index 224193c768..ebc0a078cc 100644 --- a/src/CommandLine/Commands/AnalyzeCommand.cs +++ b/src/CommandLine/Commands/AnalyzeCommand.cs @@ -28,8 +28,6 @@ public AnalyzeCommand(AnalyzeCommandLineOptions options, DiagnosticSeverity seve public override async Task ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) { - AssemblyResolver.Register(); - var codeAnalyzerOptions = new CodeAnalyzerOptions( fileSystemFilter: FileSystemFilter, ignoreAnalyzerReferences: Options.IgnoreAnalyzerReferences, diff --git a/src/CommandLine/Commands/FindSymbolsCommand.cs b/src/CommandLine/Commands/FindSymbolsCommand.cs index 3579e352a5..05806f1e57 100644 --- a/src/CommandLine/Commands/FindSymbolsCommand.cs +++ b/src/CommandLine/Commands/FindSymbolsCommand.cs @@ -42,8 +42,6 @@ internal class FindSymbolsCommand : MSBuildWorkspaceCommand public override async Task ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) { - AssemblyResolver.Register(); - HashSet ignoredSymbolIds = (Options.IgnoredSymbolIds.Any()) ? new HashSet(Options.IgnoredSymbolIds) : null; diff --git a/src/CommandLine/Commands/FixCommand.cs b/src/CommandLine/Commands/FixCommand.cs index 13ef369792..2d91ffd487 100644 --- a/src/CommandLine/Commands/FixCommand.cs +++ b/src/CommandLine/Commands/FixCommand.cs @@ -45,8 +45,6 @@ internal class FixCommand : MSBuildWorkspaceCommand public override async Task ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) { - AssemblyResolver.Register(); - var codeFixerOptions = new CodeFixerOptions( fileSystemFilter: FileSystemFilter, severityLevel: SeverityLevel, diff --git a/src/CommandLine/Commands/GenerateDocCommand.cs b/src/CommandLine/Commands/GenerateDocCommand.cs index 9828378659..907358e96c 100644 --- a/src/CommandLine/Commands/GenerateDocCommand.cs +++ b/src/CommandLine/Commands/GenerateDocCommand.cs @@ -89,8 +89,6 @@ internal class GenerateDocCommand : MSBuildWorkspaceCommand public override async Task ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) { - AssemblyResolver.Register(); - var documentationOptions = new DocumentationOptions() { RootFileHeading = Options.Heading, diff --git a/src/CommandLine/Commands/GenerateDocRootCommand.cs b/src/CommandLine/Commands/GenerateDocRootCommand.cs index 15c7c0709c..53fd0290e5 100644 --- a/src/CommandLine/Commands/GenerateDocRootCommand.cs +++ b/src/CommandLine/Commands/GenerateDocRootCommand.cs @@ -60,8 +60,6 @@ internal class GenerateDocRootCommand : MSBuildWorkspaceCommand public override async Task ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) { - AssemblyResolver.Register(); - var documentationOptions = new DocumentationOptions() { RootFileHeading = Options.Heading, diff --git a/src/CommandLine/Commands/ListSymbolsCommand.cs b/src/CommandLine/Commands/ListSymbolsCommand.cs index 1650cf3e4d..9bb0881407 100644 --- a/src/CommandLine/Commands/ListSymbolsCommand.cs +++ b/src/CommandLine/Commands/ListSymbolsCommand.cs @@ -53,8 +53,6 @@ internal class ListSymbolsCommand : MSBuildWorkspaceCommand public override async Task ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) { - AssemblyResolver.Register(); - var format = new DefinitionListFormat( layout: Layout, parts: SymbolDefinitionPartFilter.All & ~IgnoredParts, diff --git a/src/CommandLine/Commands/RenameSymbolCommand.cs b/src/CommandLine/Commands/RenameSymbolCommand.cs index c4cc0c7d7e..e23af41da9 100644 --- a/src/CommandLine/Commands/RenameSymbolCommand.cs +++ b/src/CommandLine/Commands/RenameSymbolCommand.cs @@ -51,8 +51,6 @@ internal class RenameSymbolCommand : MSBuildWorkspaceCommand ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) { - AssemblyResolver.Register(); - SymbolRenameState renamer = null; if (projectOrSolution.IsProject) diff --git a/src/CommandLine/Commands/SpellcheckCommand.cs b/src/CommandLine/Commands/SpellcheckCommand.cs index e4d7b20f0f..3c38891087 100644 --- a/src/CommandLine/Commands/SpellcheckCommand.cs +++ b/src/CommandLine/Commands/SpellcheckCommand.cs @@ -44,8 +44,6 @@ internal class SpellcheckCommand : MSBuildWorkspaceCommand ExecuteAsync(ProjectOrSolution projectOrSolution, CancellationToken cancellationToken = default) { - AssemblyResolver.Register(); - VisibilityFilter visibilityFilter = Visibility switch { Visibility.Public => VisibilityFilter.All,