Skip to content

Commit 7112409

Browse files
authored
Merge pull request #14723 from tamasvajk/standalone/include-nuget-restored-folders
C#: Include all (legacy) nuget restored folders in standalone references
2 parents 94d08aa + 5c05a4c commit 7112409

File tree

7 files changed

+308
-1
lines changed

7 files changed

+308
-1
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public sealed class DependencyManager : IDisposable
3131
private readonly IDotNet dotnet;
3232
private readonly FileContent fileContent;
3333
private readonly TemporaryDirectory packageDirectory;
34+
private readonly TemporaryDirectory legacyPackageDirectory;
3435
private readonly TemporaryDirectory missingPackageDirectory;
3536
private readonly TemporaryDirectory tempWorkingDirectory;
3637
private readonly bool cleanupTempWorkingDirectory;
@@ -52,6 +53,7 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
5253
this.sourceDir = new DirectoryInfo(srcDir);
5354

5455
packageDirectory = new TemporaryDirectory(ComputeTempDirectory(sourceDir.FullName));
56+
legacyPackageDirectory = new TemporaryDirectory(ComputeTempDirectory(sourceDir.FullName, "legacypackages"));
5557
missingPackageDirectory = new TemporaryDirectory(ComputeTempDirectory(sourceDir.FullName, "missingpackages"));
5658

5759
tempWorkingDirectory = new TemporaryDirectory(FileUtils.GetTemporaryWorkingDirectory(out cleanupTempWorkingDirectory));
@@ -89,8 +91,21 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
8991
{
9092
try
9193
{
92-
var nuget = new NugetPackages(sourceDir.FullName, packageDirectory, progressMonitor);
94+
var nuget = new NugetPackages(sourceDir.FullName, legacyPackageDirectory, progressMonitor);
9395
nuget.InstallPackages();
96+
97+
var nugetPackageDlls = legacyPackageDirectory.DirInfo.GetFiles("*.dll", new EnumerationOptions { RecurseSubdirectories = true });
98+
var nugetPackageDllPaths = nugetPackageDlls.Select(f => f.FullName).ToHashSet();
99+
var excludedPaths = nugetPackageDllPaths
100+
.Where(path => IsPathInSubfolder(path, legacyPackageDirectory.DirInfo.FullName, "tools"));
101+
102+
foreach (var excludedPath in excludedPaths)
103+
{
104+
progressMonitor.LogInfo($"Excluded Nuget DLL: {excludedPath}");
105+
}
106+
107+
nugetPackageDllPaths.ExceptWith(excludedPaths);
108+
dllPaths.UnionWith(nugetPackageDllPaths);
94109
}
95110
catch (FileNotFoundException)
96111
{
@@ -165,6 +180,14 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
165180
DateTime.Now - startTime);
166181
}
167182

183+
private static bool IsPathInSubfolder(string path, string rootFolder, string subFolder)
184+
{
185+
return path.IndexOf(
186+
$"{Path.DirectorySeparatorChar}{subFolder}{Path.DirectorySeparatorChar}",
187+
rootFolder.Length,
188+
StringComparison.InvariantCultureIgnoreCase) >= 0;
189+
}
190+
168191
private void RemoveNugetAnalyzerReferences()
169192
{
170193
if (!options.UseNuGet)
@@ -740,6 +763,7 @@ public void Dispose(TemporaryDirectory? dir, string name)
740763
public void Dispose()
741764
{
742765
Dispose(packageDirectory, "package");
766+
Dispose(legacyPackageDirectory, "legacy package");
743767
Dispose(missingPackageDirectory, "missing package");
744768
if (cleanupTempWorkingDirectory)
745769
{
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
| 4.8-api/Accessibility.dll |
2+
| 4.8-api/Commons.Xml.Relaxng.dll |
3+
| 4.8-api/CustomMarshalers.dll |
4+
| 4.8-api/Facades/Microsoft.Win32.Primitives.dll |
5+
| 4.8-api/Facades/System.AppContext.dll |
6+
| 4.8-api/Facades/System.Collections.Concurrent.dll |
7+
| 4.8-api/Facades/System.Collections.NonGeneric.dll |
8+
| 4.8-api/Facades/System.Collections.Specialized.dll |
9+
| 4.8-api/Facades/System.Collections.dll |
10+
| 4.8-api/Facades/System.ComponentModel.Annotations.dll |
11+
| 4.8-api/Facades/System.ComponentModel.EventBasedAsync.dll |
12+
| 4.8-api/Facades/System.ComponentModel.Primitives.dll |
13+
| 4.8-api/Facades/System.ComponentModel.TypeConverter.dll |
14+
| 4.8-api/Facades/System.ComponentModel.dll |
15+
| 4.8-api/Facades/System.Console.dll |
16+
| 4.8-api/Facades/System.Data.Common.dll |
17+
| 4.8-api/Facades/System.Diagnostics.Contracts.dll |
18+
| 4.8-api/Facades/System.Diagnostics.Debug.dll |
19+
| 4.8-api/Facades/System.Diagnostics.FileVersionInfo.dll |
20+
| 4.8-api/Facades/System.Diagnostics.Process.dll |
21+
| 4.8-api/Facades/System.Diagnostics.StackTrace.dll |
22+
| 4.8-api/Facades/System.Diagnostics.TextWriterTraceListener.dll |
23+
| 4.8-api/Facades/System.Diagnostics.Tools.dll |
24+
| 4.8-api/Facades/System.Diagnostics.TraceSource.dll |
25+
| 4.8-api/Facades/System.Drawing.Primitives.dll |
26+
| 4.8-api/Facades/System.Dynamic.Runtime.dll |
27+
| 4.8-api/Facades/System.Globalization.Calendars.dll |
28+
| 4.8-api/Facades/System.Globalization.Extensions.dll |
29+
| 4.8-api/Facades/System.Globalization.dll |
30+
| 4.8-api/Facades/System.IO.Compression.ZipFile.dll |
31+
| 4.8-api/Facades/System.IO.FileSystem.DriveInfo.dll |
32+
| 4.8-api/Facades/System.IO.FileSystem.Primitives.dll |
33+
| 4.8-api/Facades/System.IO.FileSystem.Watcher.dll |
34+
| 4.8-api/Facades/System.IO.FileSystem.dll |
35+
| 4.8-api/Facades/System.IO.IsolatedStorage.dll |
36+
| 4.8-api/Facades/System.IO.MemoryMappedFiles.dll |
37+
| 4.8-api/Facades/System.IO.Pipes.dll |
38+
| 4.8-api/Facades/System.IO.UnmanagedMemoryStream.dll |
39+
| 4.8-api/Facades/System.IO.dll |
40+
| 4.8-api/Facades/System.Linq.Expressions.dll |
41+
| 4.8-api/Facades/System.Linq.Parallel.dll |
42+
| 4.8-api/Facades/System.Linq.Queryable.dll |
43+
| 4.8-api/Facades/System.Linq.dll |
44+
| 4.8-api/Facades/System.Net.Http.Rtc.dll |
45+
| 4.8-api/Facades/System.Net.NameResolution.dll |
46+
| 4.8-api/Facades/System.Net.NetworkInformation.dll |
47+
| 4.8-api/Facades/System.Net.Ping.dll |
48+
| 4.8-api/Facades/System.Net.Primitives.dll |
49+
| 4.8-api/Facades/System.Net.Requests.dll |
50+
| 4.8-api/Facades/System.Net.Security.dll |
51+
| 4.8-api/Facades/System.Net.Sockets.dll |
52+
| 4.8-api/Facades/System.Net.WebHeaderCollection.dll |
53+
| 4.8-api/Facades/System.Net.WebSockets.Client.dll |
54+
| 4.8-api/Facades/System.Net.WebSockets.dll |
55+
| 4.8-api/Facades/System.ObjectModel.dll |
56+
| 4.8-api/Facades/System.Reflection.Emit.ILGeneration.dll |
57+
| 4.8-api/Facades/System.Reflection.Emit.Lightweight.dll |
58+
| 4.8-api/Facades/System.Reflection.Emit.dll |
59+
| 4.8-api/Facades/System.Reflection.Extensions.dll |
60+
| 4.8-api/Facades/System.Reflection.Primitives.dll |
61+
| 4.8-api/Facades/System.Reflection.dll |
62+
| 4.8-api/Facades/System.Resources.Reader.dll |
63+
| 4.8-api/Facades/System.Resources.ResourceManager.dll |
64+
| 4.8-api/Facades/System.Resources.Writer.dll |
65+
| 4.8-api/Facades/System.Runtime.CompilerServices.VisualC.dll |
66+
| 4.8-api/Facades/System.Runtime.Extensions.dll |
67+
| 4.8-api/Facades/System.Runtime.Handles.dll |
68+
| 4.8-api/Facades/System.Runtime.InteropServices.RuntimeInformation.dll |
69+
| 4.8-api/Facades/System.Runtime.InteropServices.WindowsRuntime.dll |
70+
| 4.8-api/Facades/System.Runtime.InteropServices.dll |
71+
| 4.8-api/Facades/System.Runtime.Numerics.dll |
72+
| 4.8-api/Facades/System.Runtime.Serialization.Formatters.dll |
73+
| 4.8-api/Facades/System.Runtime.Serialization.Json.dll |
74+
| 4.8-api/Facades/System.Runtime.Serialization.Primitives.dll |
75+
| 4.8-api/Facades/System.Runtime.Serialization.Xml.dll |
76+
| 4.8-api/Facades/System.Runtime.dll |
77+
| 4.8-api/Facades/System.Security.Claims.dll |
78+
| 4.8-api/Facades/System.Security.Cryptography.Algorithms.dll |
79+
| 4.8-api/Facades/System.Security.Cryptography.Csp.dll |
80+
| 4.8-api/Facades/System.Security.Cryptography.Encoding.dll |
81+
| 4.8-api/Facades/System.Security.Cryptography.Primitives.dll |
82+
| 4.8-api/Facades/System.Security.Cryptography.X509Certificates.dll |
83+
| 4.8-api/Facades/System.Security.Principal.dll |
84+
| 4.8-api/Facades/System.Security.SecureString.dll |
85+
| 4.8-api/Facades/System.ServiceModel.Duplex.dll |
86+
| 4.8-api/Facades/System.ServiceModel.Http.dll |
87+
| 4.8-api/Facades/System.ServiceModel.NetTcp.dll |
88+
| 4.8-api/Facades/System.ServiceModel.Primitives.dll |
89+
| 4.8-api/Facades/System.ServiceModel.Security.dll |
90+
| 4.8-api/Facades/System.Text.Encoding.Extensions.dll |
91+
| 4.8-api/Facades/System.Text.Encoding.dll |
92+
| 4.8-api/Facades/System.Text.RegularExpressions.dll |
93+
| 4.8-api/Facades/System.Threading.Overlapped.dll |
94+
| 4.8-api/Facades/System.Threading.Tasks.Parallel.dll |
95+
| 4.8-api/Facades/System.Threading.Tasks.dll |
96+
| 4.8-api/Facades/System.Threading.Thread.dll |
97+
| 4.8-api/Facades/System.Threading.ThreadPool.dll |
98+
| 4.8-api/Facades/System.Threading.Timer.dll |
99+
| 4.8-api/Facades/System.Threading.dll |
100+
| 4.8-api/Facades/System.ValueTuple.dll |
101+
| 4.8-api/Facades/System.Xml.ReaderWriter.dll |
102+
| 4.8-api/Facades/System.Xml.XDocument.dll |
103+
| 4.8-api/Facades/System.Xml.XPath.XDocument.dll |
104+
| 4.8-api/Facades/System.Xml.XPath.dll |
105+
| 4.8-api/Facades/System.Xml.XmlDocument.dll |
106+
| 4.8-api/Facades/System.Xml.XmlSerializer.dll |
107+
| 4.8-api/Facades/netstandard.dll |
108+
| 4.8-api/I18N.CJK.dll |
109+
| 4.8-api/I18N.MidEast.dll |
110+
| 4.8-api/I18N.Other.dll |
111+
| 4.8-api/I18N.Rare.dll |
112+
| 4.8-api/I18N.West.dll |
113+
| 4.8-api/I18N.dll |
114+
| 4.8-api/IBM.Data.DB2.dll |
115+
| 4.8-api/Microsoft.Build.Engine.dll |
116+
| 4.8-api/Microsoft.Build.Framework.dll |
117+
| 4.8-api/Microsoft.Build.Tasks.v4.0.dll |
118+
| 4.8-api/Microsoft.Build.Utilities.v4.0.dll |
119+
| 4.8-api/Microsoft.Build.dll |
120+
| 4.8-api/Microsoft.CSharp.dll |
121+
| 4.8-api/Microsoft.VisualBasic.dll |
122+
| 4.8-api/Microsoft.VisualC.dll |
123+
| 4.8-api/Microsoft.Web.Infrastructure.dll |
124+
| 4.8-api/Mono.C5.dll |
125+
| 4.8-api/Mono.CSharp.dll |
126+
| 4.8-api/Mono.Cairo.dll |
127+
| 4.8-api/Mono.CodeContracts.dll |
128+
| 4.8-api/Mono.CompilerServices.SymbolWriter.dll |
129+
| 4.8-api/Mono.Data.Sqlite.dll |
130+
| 4.8-api/Mono.Data.Tds.dll |
131+
| 4.8-api/Mono.Debugger.Soft.dll |
132+
| 4.8-api/Mono.Http.dll |
133+
| 4.8-api/Mono.Management.dll |
134+
| 4.8-api/Mono.Messaging.RabbitMQ.dll |
135+
| 4.8-api/Mono.Messaging.dll |
136+
| 4.8-api/Mono.Options.dll |
137+
| 4.8-api/Mono.Parallel.dll |
138+
| 4.8-api/Mono.Posix.dll |
139+
| 4.8-api/Mono.Security.Win32.dll |
140+
| 4.8-api/Mono.Security.dll |
141+
| 4.8-api/Mono.Simd.dll |
142+
| 4.8-api/Mono.Tasklets.dll |
143+
| 4.8-api/Mono.WebBrowser.dll |
144+
| 4.8-api/Novell.Directory.Ldap.dll |
145+
| 4.8-api/PEAPI.dll |
146+
| 4.8-api/RabbitMQ.Client.dll |
147+
| 4.8-api/SMDiagnostics.dll |
148+
| 4.8-api/System.ComponentModel.Composition.dll |
149+
| 4.8-api/System.ComponentModel.DataAnnotations.dll |
150+
| 4.8-api/System.Configuration.Install.dll |
151+
| 4.8-api/System.Configuration.dll |
152+
| 4.8-api/System.Core.dll |
153+
| 4.8-api/System.Data.DataSetExtensions.dll |
154+
| 4.8-api/System.Data.Entity.dll |
155+
| 4.8-api/System.Data.Linq.dll |
156+
| 4.8-api/System.Data.OracleClient.dll |
157+
| 4.8-api/System.Data.Services.Client.dll |
158+
| 4.8-api/System.Data.Services.dll |
159+
| 4.8-api/System.Data.dll |
160+
| 4.8-api/System.Deployment.dll |
161+
| 4.8-api/System.Design.dll |
162+
| 4.8-api/System.Diagnostics.Tracing.dll |
163+
| 4.8-api/System.DirectoryServices.Protocols.dll |
164+
| 4.8-api/System.DirectoryServices.dll |
165+
| 4.8-api/System.Drawing.Design.dll |
166+
| 4.8-api/System.Drawing.dll |
167+
| 4.8-api/System.Dynamic.dll |
168+
| 4.8-api/System.EnterpriseServices.dll |
169+
| 4.8-api/System.IO.Compression.FileSystem.dll |
170+
| 4.8-api/System.IO.Compression.dll |
171+
| 4.8-api/System.IdentityModel.Selectors.dll |
172+
| 4.8-api/System.IdentityModel.dll |
173+
| 4.8-api/System.Json.Microsoft.dll |
174+
| 4.8-api/System.Json.dll |
175+
| 4.8-api/System.Management.dll |
176+
| 4.8-api/System.Messaging.dll |
177+
| 4.8-api/System.Net.Http.Formatting.dll |
178+
| 4.8-api/System.Net.Http.WebRequest.dll |
179+
| 4.8-api/System.Net.Http.dll |
180+
| 4.8-api/System.Net.dll |
181+
| 4.8-api/System.Numerics.Vectors.dll |
182+
| 4.8-api/System.Numerics.dll |
183+
| 4.8-api/System.Reactive.Core.dll |
184+
| 4.8-api/System.Reactive.Debugger.dll |
185+
| 4.8-api/System.Reactive.Experimental.dll |
186+
| 4.8-api/System.Reactive.Interfaces.dll |
187+
| 4.8-api/System.Reactive.Linq.dll |
188+
| 4.8-api/System.Reactive.Observable.Aliases.dll |
189+
| 4.8-api/System.Reactive.PlatformServices.dll |
190+
| 4.8-api/System.Reactive.Providers.dll |
191+
| 4.8-api/System.Reactive.Runtime.Remoting.dll |
192+
| 4.8-api/System.Reactive.Windows.Forms.dll |
193+
| 4.8-api/System.Reactive.Windows.Threading.dll |
194+
| 4.8-api/System.Reflection.Context.dll |
195+
| 4.8-api/System.Runtime.Caching.dll |
196+
| 4.8-api/System.Runtime.DurableInstancing.dll |
197+
| 4.8-api/System.Runtime.Remoting.dll |
198+
| 4.8-api/System.Runtime.Serialization.Formatters.Soap.dll |
199+
| 4.8-api/System.Runtime.Serialization.dll |
200+
| 4.8-api/System.Security.dll |
201+
| 4.8-api/System.ServiceModel.Activation.dll |
202+
| 4.8-api/System.ServiceModel.Discovery.dll |
203+
| 4.8-api/System.ServiceModel.Routing.dll |
204+
| 4.8-api/System.ServiceModel.Web.dll |
205+
| 4.8-api/System.ServiceModel.dll |
206+
| 4.8-api/System.ServiceProcess.dll |
207+
| 4.8-api/System.Threading.Tasks.Dataflow.dll |
208+
| 4.8-api/System.Transactions.dll |
209+
| 4.8-api/System.Web.Abstractions.dll |
210+
| 4.8-api/System.Web.ApplicationServices.dll |
211+
| 4.8-api/System.Web.DynamicData.dll |
212+
| 4.8-api/System.Web.Extensions.Design.dll |
213+
| 4.8-api/System.Web.Extensions.dll |
214+
| 4.8-api/System.Web.Http.SelfHost.dll |
215+
| 4.8-api/System.Web.Http.WebHost.dll |
216+
| 4.8-api/System.Web.Http.dll |
217+
| 4.8-api/System.Web.Mobile.dll |
218+
| 4.8-api/System.Web.Mvc.dll |
219+
| 4.8-api/System.Web.Razor.dll |
220+
| 4.8-api/System.Web.RegularExpressions.dll |
221+
| 4.8-api/System.Web.Routing.dll |
222+
| 4.8-api/System.Web.Services.dll |
223+
| 4.8-api/System.Web.WebPages.Deployment.dll |
224+
| 4.8-api/System.Web.WebPages.Razor.dll |
225+
| 4.8-api/System.Web.WebPages.dll |
226+
| 4.8-api/System.Web.dll |
227+
| 4.8-api/System.Windows.Forms.DataVisualization.dll |
228+
| 4.8-api/System.Windows.Forms.dll |
229+
| 4.8-api/System.Windows.dll |
230+
| 4.8-api/System.Workflow.Activities.dll |
231+
| 4.8-api/System.Workflow.ComponentModel.dll |
232+
| 4.8-api/System.Workflow.Runtime.dll |
233+
| 4.8-api/System.Xaml.dll |
234+
| 4.8-api/System.Xml.Linq.dll |
235+
| 4.8-api/System.Xml.Serialization.dll |
236+
| 4.8-api/System.Xml.dll |
237+
| 4.8-api/System.dll |
238+
| 4.8-api/WebMatrix.Data.dll |
239+
| 4.8-api/WindowsBase.dll |
240+
| 4.8-api/cscompmgd.dll |
241+
| 4.8-api/mscorlib.dll |
242+
| /Newtonsoft.Json.6.0.4/lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.dll |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import csharp
2+
3+
private string getPath(Assembly a) {
4+
not a.getCompilation().getOutputAssembly() = a and
5+
exists(string s | s = a.getFile().getAbsolutePath() |
6+
result =
7+
s.substring(s.indexOf("GitHub/packages/") + "GitHub/packages/".length() + 16, s.length())
8+
or
9+
result =
10+
s.substring(s.indexOf("GitHub/legacypackages/") + "GitHub/legacypackages/".length() + 16,
11+
s.length())
12+
or
13+
result = s.substring(s.indexOf("lib/mono/") + "lib/mono/".length(), s.length())
14+
or
15+
result = s and
16+
not exists(s.indexOf("GitHub/packages/")) and
17+
not exists(s.indexOf("GitHub/legacypackages/")) and
18+
not exists(s.indexOf("lib/mono/"))
19+
)
20+
}
21+
22+
from Assembly a
23+
select getPath(a)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Program
2+
{
3+
static void Main(string[] args)
4+
{
5+
}
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net461" />
4+
<package id="NUnit.ConsoleRunner" version="3.12.0" />
5+
</packages>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
4+
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from create_database_utils import *
2+
3+
run_codeql_database_create([], lang="csharp", extra_args=["--extractor-option=buildless=true", "--extractor-option=cil=false"])

0 commit comments

Comments
 (0)