Skip to content

Commit 890cba6

Browse files
committed
C#: Disregard _._ dependencies and only default to use an entire framework in case the compile section is empty.
1 parent e89fe8d commit 890cba6

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,18 @@ private void AddPackageDependencies(JObject json, DependencyContainer dependenci
100100
return;
101101
}
102102

103-
// If this is a .NET framework reference then include everything.
104-
if (FrameworkPackageNames.AllFrameworks.Any(framework => name.StartsWith(framework)))
103+
if (info.Compile is null || !info.Compile.Any())
105104
{
106-
dependencies.AddFramework(name);
107-
}
108-
else
109-
{
110-
info.Compile?
111-
.ForEach(r => dependencies.Add(name, r.Key));
105+
// If this is a framework reference then include everything.
106+
if (FrameworkPackageNames.AllFrameworks.Any(framework => name.StartsWith(framework)))
107+
{
108+
dependencies.AddFramework(name);
109+
}
110+
return;
112111
}
112+
113+
info.Compile
114+
.ForEach(r => dependencies.Add(name, r.Key));
113115
});
114116

115117
return;

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ internal class DependencyContainer
2020
public HashSet<string> Packages { get; } = new();
2121

2222
/// <summary>
23-
/// In most cases paths in asset files point to dll's or the empty _._ file, which
24-
/// is sometimes there to avoid the directory being empty.
25-
/// That is, if the path specifically adds a .dll we use that, otherwise we as a fallback
26-
/// add the entire directory (which should be fine in case of _._ as well).
23+
/// If the path specifically adds a .dll we use that, otherwise we as a fallback
24+
/// add the entire directory.
2725
/// </summary>
2826
private static string ParseFilePath(string path)
2927
{
@@ -47,6 +45,13 @@ public void Add(string package, string dependency)
4745
var p = package.Replace('/', Path.DirectorySeparatorChar);
4846
var d = dependency.Replace('/', Path.DirectorySeparatorChar);
4947

48+
// In most cases paths in asset files point to dll's or the empty _._ file.
49+
// That is, for _._ we don't need to add anything.
50+
if (Path.GetFileName(d) == "_._")
51+
{
52+
return;
53+
}
54+
5055
var path = Path.Combine(p, ParseFilePath(d));
5156
Paths.Add(path);
5257
Packages.Add(GetPackageName(p));

0 commit comments

Comments
 (0)