Skip to content

Commit d44d980

Browse files
committed
C#: Exclude tools folders in legacy nuget packages
1 parent fd99e1f commit d44d980

File tree

3 files changed

+21
-106
lines changed

3 files changed

+21
-106
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/DependencyManager.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,19 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
9191
{
9292
var nuget = new NugetPackages(sourceDir.FullName, packageDirectory, progressMonitor);
9393
nuget.InstallPackages();
94-
dllPaths.UnionWith(GetAllPackageDirectories());
94+
95+
var nugetPackageDlls = packageDirectory.DirInfo.GetFiles("*.dll", new EnumerationOptions { RecurseSubdirectories = true });
96+
var nugetPackageDllPaths = nugetPackageDlls.Select(f => f.FullName).ToHashSet();
97+
var excludedPaths = nugetPackageDllPaths
98+
.Where(path => IsPathInSubfolder(path, packageDirectory.DirInfo.FullName, "tools"));
99+
100+
foreach (var excludedPath in excludedPaths)
101+
{
102+
progressMonitor.LogInfo($"Excluded DLL: {excludedPath}");
103+
}
104+
105+
nugetPackageDllPaths.ExceptWith(excludedPaths);
106+
dllPaths.UnionWith(nugetPackageDllPaths);
95107
}
96108
catch (FileNotFoundException)
97109
{
@@ -166,6 +178,14 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
166178
DateTime.Now - startTime);
167179
}
168180

181+
private static bool IsPathInSubfolder(string path, string rootFolder, string subFolder)
182+
{
183+
return path.IndexOf(
184+
$"{Path.DirectorySeparatorChar}{subFolder}{Path.DirectorySeparatorChar}",
185+
rootFolder.Length,
186+
StringComparison.InvariantCultureIgnoreCase) >= 0;
187+
}
188+
169189
private void RemoveNugetAnalyzerReferences()
170190
{
171191
if (!options.UseNuGet)

csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget/Assemblies.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,4 @@
239239
| 4.8-api/WindowsBase.dll |
240240
| 4.8-api/cscompmgd.dll |
241241
| 4.8-api/mscorlib.dll |
242-
| /NUnit.ConsoleRunner.3.12.0/tools/nunit.engine.api.dll |
243-
| /NUnit.ConsoleRunner.3.12.0/tools/nunit.engine.core.dll |
244-
| /NUnit.ConsoleRunner.3.12.0/tools/nunit.engine.dll |
245-
| /NUnit.ConsoleRunner.3.12.0/tools/testcentric.engine.metadata.dll |
246242
| /Newtonsoft.Json.6.0.4/lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.dll |

csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget/DB-CHECK.actual

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)