Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle" Version="$(MicrosoftCodeAnalysisPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.Features" Version="$(MicrosoftCodeAnalysisPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="$(MicrosoftCodeAnalysisPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="$(MicrosoftCodeAnalysisWorkspacesCommonPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="$(MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion)" />
<PackageVersion Include="Microsoft.Css.Parser" Version="$(MicrosoftCssParserVersion)" />
<PackageVersion Include="Microsoft.DiaSymReader" Version="$(MicrosoftDiaSymReaderVersion)" />
Expand Down
4 changes: 4 additions & 0 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>911cf5f462960bdd01df1ea3c0d0c217b3c3838b</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.13.0-3.25057.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>911cf5f462960bdd01df1ea3c0d0c217b3c3838b</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.13.0-3.25057.3">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>911cf5f462960bdd01df1ea3c0d0c217b3c3838b</Sha>
Expand Down
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
<MicrosoftCodeAnalysisCSharpPackageVersion>4.13.0-3.25057.3</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpCodeStylePackageVersion>4.13.0-3.25057.3</MicrosoftCodeAnalysisCSharpCodeStylePackageVersion>
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>4.13.0-3.25057.3</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>4.13.0-3.25057.3</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>4.13.0-3.25057.3</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>4.13.0-3.25057.3</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace Microsoft.DotNet.GenAPI
public interface IAssemblySymbolWriter
{
/// <summary>
/// Process a given assembly symbol.
/// Write a given assembly symbol to the instance's desired output.
/// </summary>
/// <param name="assemblySymbol"><see cref="IAssemblySymbol"/> representing the loaded assembly.</param>
/// <param name="assemblySymbol">An assembly symbol representing the loaded assembly.</param>
void WriteAssembly(IAssemblySymbol assemblySymbol);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ private static SyntaxList<AttributeListSyntax> FromAttributeData(IEnumerable<Att
}

// Build dummy field from a type, field name, and attribute list.
private static SyntaxNode CreateDummyField(string typ, string fieldName, SyntaxList<AttributeListSyntax> attrs, bool isReadonly)
private static SyntaxNode CreateDummyField(string type, string fieldName, SyntaxList<AttributeListSyntax> attrs, bool isReadonly)
{
List<SyntaxToken> 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<VariableDeclaratorSyntax>(
SyntaxFactory.VariableDeclarator(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@ public class AssemblySymbolLoader : IAssemblySymbolLoader
/// </summary>
public const string AssemblyReferenceNotFoundErrorCode = "CP1002";

/// <summary>
/// Creates an assembly symbol loader and its corresponding assembly symbols from the given DLL files in the filesystem.
/// </summary>
/// <param name="logger">The logger instance to use for message logging.</param>
/// <param name="assembliesPaths">A collection of paths where the assembly DLLs should be searched.</param>
/// <param name="assemblyReferencesPaths">An optional collection of paths where the assembly references should be searched.</param>
/// <param name="respectInternals">Whether to include internal symbols or not.</param>
/// <returns>A tuple containing an assembly symbol loader and its corresponding dictionary of assembly symbols.</returns>
public static (AssemblySymbolLoader, Dictionary<string, IAssemblySymbol>) CreateFromFiles(ILog logger, string[] assembliesPaths, string[]? assemblyReferencesPaths, bool respectInternals = false)
{
if (assembliesPaths.Length == 0)
{
return (new AssemblySymbolLoader(logger, resolveAssemblyReferences: true, includeInternalSymbols: respectInternals), new Dictionary<string, IAssemblySymbol>());
}

bool atLeastOneReferencePath = assemblyReferencesPaths?.Count() > 0;
AssemblySymbolLoader loader = new(logger, resolveAssemblyReferences: atLeastOneReferencePath, respectInternals);
if (atLeastOneReferencePath)
{
loader.AddReferenceSearchPaths(assemblyReferencesPaths!);
}
Dictionary<string, IAssemblySymbol> dictionary = new(loader.LoadAssembliesAsDictionary(assembliesPaths));

return (loader, dictionary);
}

/// <summary>
/// Creates a new instance of the <see cref="AssemblySymbolLoader"/> class.
/// </summary>
Expand Down Expand Up @@ -295,6 +321,29 @@ private List<MetadataReference> LoadFromPaths(IEnumerable<string> paths, Immutab
return result;
}

// Loads a set of assemblies from the filesystem and gets their corresponding <see cref="IAssemblySymbol"/> instances as a dictionary.
private IDictionary<string, IAssemblySymbol> 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<string> fileNames = paths.Select(path => Path.GetFileName(path)).ToImmutableHashSet();
List<MetadataReference> assembliesToReturn = LoadFromPaths(paths, fileNames);

// Create IAssemblySymbols out of the MetadataReferences.
// Doing this after resolving references to make sure that references are available.
Dictionary<string, IAssemblySymbol> 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<string>? referenceAssemblyNamesToIgnore = null)
{
// Roslyn doesn't support having two assemblies as references with the same identity and then getting the symbol for it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down