diff --git a/Directory.Packages.props b/Directory.Packages.props index 37f12c935a34..cde36c909357 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -28,6 +28,7 @@ + diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 567f4cf9b42b..4a72e20104cf 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -131,6 +131,10 @@ https://github.com/dotnet/roslyn 911cf5f462960bdd01df1ea3c0d0c217b3c3838b + + https://github.com/dotnet/roslyn + 911cf5f462960bdd01df1ea3c0d0c217b3c3838b + https://github.com/dotnet/roslyn 911cf5f462960bdd01df1ea3c0d0c217b3c3838b diff --git a/eng/Versions.props b/eng/Versions.props index 568ef68bf68c..902e8722dfa0 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -215,6 +215,7 @@ 4.13.0-3.25057.3 4.13.0-3.25057.3 4.13.0-3.25057.3 + 4.13.0-3.25057.3 4.13.0-3.25057.3 4.13.0-3.25057.3 diff --git a/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/IAssemblySymbolWriter.cs b/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/IAssemblySymbolWriter.cs index a739ca961575..e093037b8a78 100644 --- a/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/IAssemblySymbolWriter.cs +++ b/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/IAssemblySymbolWriter.cs @@ -11,9 +11,9 @@ namespace Microsoft.DotNet.GenAPI public interface IAssemblySymbolWriter { /// - /// Process a given assembly symbol. + /// Write a given assembly symbol to the instance's desired output. /// - /// representing the loaded assembly. + /// An assembly symbol representing the loaded assembly. void WriteAssembly(IAssemblySymbol assemblySymbol); } } diff --git a/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/INamedTypeSymbolExtensions.cs b/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/INamedTypeSymbolExtensions.cs index 6d5d6ec8e054..4ef1ecedcf6d 100644 --- a/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/INamedTypeSymbolExtensions.cs +++ b/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/INamedTypeSymbolExtensions.cs @@ -69,14 +69,14 @@ private static SyntaxList FromAttributeData(IEnumerable attrs, bool isReadonly) + private static SyntaxNode CreateDummyField(string type, string fieldName, SyntaxList attrs, bool isReadonly) { List modifiers = new() { SyntaxFactory.Token(SyntaxKind.PrivateKeyword) }; if (isReadonly) modifiers.Add(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword)); SyntaxNode declaration = SyntaxFactory.FieldDeclaration( SyntaxFactory.VariableDeclaration( - SyntaxFactory.ParseTypeName(typ)) + SyntaxFactory.ParseTypeName(type)) .WithVariables( SyntaxFactory.SingletonSeparatedList( SyntaxFactory.VariableDeclarator( diff --git a/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/SyntaxGeneratorExtensions.cs b/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/SyntaxGeneratorExtensions.cs index 6618d47a20b1..3af277f65c4a 100644 --- a/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/SyntaxGeneratorExtensions.cs +++ b/src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/SyntaxGeneratorExtensions.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Transactions; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; diff --git a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs index 1d6921dd1f92..5fda5bdaac45 100644 --- a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs +++ b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs @@ -35,6 +35,32 @@ public class AssemblySymbolLoader : IAssemblySymbolLoader /// public const string AssemblyReferenceNotFoundErrorCode = "CP1002"; + /// + /// Creates an assembly symbol loader and its corresponding assembly symbols from the given DLL files in the filesystem. + /// + /// The logger instance to use for message logging. + /// A collection of paths where the assembly DLLs should be searched. + /// An optional collection of paths where the assembly references should be searched. + /// Whether to include internal symbols or not. + /// A tuple containing an assembly symbol loader and its corresponding dictionary of assembly symbols. + public static (AssemblySymbolLoader, Dictionary) CreateFromFiles(ILog logger, string[] assembliesPaths, string[]? assemblyReferencesPaths, bool respectInternals = false) + { + if (assembliesPaths.Length == 0) + { + return (new AssemblySymbolLoader(logger, resolveAssemblyReferences: true, includeInternalSymbols: respectInternals), new Dictionary()); + } + + bool atLeastOneReferencePath = assemblyReferencesPaths?.Count() > 0; + AssemblySymbolLoader loader = new(logger, resolveAssemblyReferences: atLeastOneReferencePath, respectInternals); + if (atLeastOneReferencePath) + { + loader.AddReferenceSearchPaths(assemblyReferencesPaths!); + } + Dictionary dictionary = new(loader.LoadAssembliesAsDictionary(assembliesPaths)); + + return (loader, dictionary); + } + /// /// Creates a new instance of the class. /// @@ -295,6 +321,29 @@ private List LoadFromPaths(IEnumerable paths, Immutab return result; } + // Loads a set of assemblies from the filesystem and gets their corresponding instances as a dictionary. + private IDictionary LoadAssembliesAsDictionary(params string[] paths) + { + // First resolve all assemblies that are passed in and create metadata references out of them. + // Reference assemblies of the passed in assemblies that themselves are passed in, will be skipped to be resolved, + // as they are resolved as part of the loop below. + ImmutableHashSet fileNames = paths.Select(path => Path.GetFileName(path)).ToImmutableHashSet(); + List assembliesToReturn = LoadFromPaths(paths, fileNames); + + // Create IAssemblySymbols out of the MetadataReferences. + // Doing this after resolving references to make sure that references are available. + Dictionary assemblySymbols = []; + foreach (MetadataReference metadataReference in assembliesToReturn) + { + if (_cSharpCompilation.GetAssemblyOrModuleSymbol(metadataReference) is IAssemblySymbol assemblySymbol) + { + assemblySymbols.Add(assemblySymbol.Name, assemblySymbol); + } + } + + return assemblySymbols; + } + private MetadataReference CreateOrGetMetadataReferenceFromPath(string path, ImmutableHashSet? referenceAssemblyNamesToIgnore = null) { // Roslyn doesn't support having two assemblies as references with the same identity and then getting the symbol for it. diff --git a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/Filtering/ImplicitSymbolFilter.cs b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/Filtering/ImplicitSymbolFilter.cs index 1fe0da2e0450..a86ee9cff67a 100644 --- a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/Filtering/ImplicitSymbolFilter.cs +++ b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/Filtering/ImplicitSymbolFilter.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.CodeAnalysis; -using Microsoft.DotNet.ApiSymbolExtensions; -using Microsoft.DotNet.ApiSymbolExtensions.Filtering; namespace Microsoft.DotNet.ApiSymbolExtensions.Filtering {