C#: Also use AssemblyLookupLocation for framework dlls.

This commit is contained in:
Michael Nebel
2024-04-09 16:16:21 +02:00
parent 99f0ed26e9
commit 3b42dc25a1
2 changed files with 23 additions and 37 deletions

View File

@@ -10,7 +10,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
/// Used to represent a path to an assembly or a directory containing assemblies
/// and a selector function to determine which files to include, when indexing the assemblies.
/// </summary>
internal sealed class AssemblyLookupLocation(string p, Func<string, bool> includeFileName)
internal sealed class AssemblyLookupLocation(string p, Func<string, bool> includeFileName, bool indexSubdirectories = true)
{
public string Path => p;
@@ -26,22 +26,29 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
/// <param name="dir">The directory to index.</param>
private void AddReferenceDirectory(List<string> dllsToIndex, ILogger logger)
{
var dlls = new DirectoryInfo(p).EnumerateFiles("*.dll", new EnumerationOptions { RecurseSubdirectories = true, MatchCasing = MatchCasing.CaseInsensitive, AttributesToSkip = FileAttributes.None });
if (!dlls.Any())
try
{
logger.LogWarning($"AssemblyLookupLocation: No DLLs found in the path '{p}'.");
return;
var dlls = new DirectoryInfo(p).EnumerateFiles("*.dll", new EnumerationOptions { RecurseSubdirectories = indexSubdirectories, MatchCasing = MatchCasing.CaseInsensitive, AttributesToSkip = FileAttributes.None });
if (!dlls.Any())
{
logger.LogWarning($"AssemblyLookupLocation: No DLLs found in the path '{p}'.");
return;
}
foreach (var dll in dlls)
{
if (includeFileName(dll.Name))
{
dllsToIndex.Add(dll.FullName);
}
else
{
logger.LogInfo($"AssemblyLookupLocation: Skipping {dll.FullName}.");
}
}
}
foreach (var dll in dlls)
catch (Exception e)
{
if (includeFileName(dll.Name))
{
dllsToIndex.Add(dll.FullName);
}
else
{
logger.LogInfo($"AssemblyLookupLocation: Skipping {dll.FullName}.");
}
logger.LogError($"AssemblyLookupLocation: Error while searching for DLLs in '{p}': {e.Message}");
}
}