Skip to content

Commit 1b37c66

Browse files
committed
C#: Only consider latest version of dotnet framework flavors
1 parent 30e5e74 commit 1b37c66

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,32 @@ private void AddNetFrameworkDlls(ISet<string> dllPaths, ISet<string> frameworkLo
237237
var packagesInPrioOrder = FrameworkPackageNames.NetFrameworks;
238238

239239
var frameworkPath = packagesInPrioOrder
240-
.Select((s, index) => (Index: index, Path: GetPackageDirectory(s)))
241-
.FirstOrDefault(pair => pair.Path is not null);
240+
.Select((s, index) => (Index: index, Path: GetPackageDirectory(s)))
241+
.FirstOrDefault(pair => pair.Path is not null);
242242

243243
if (frameworkPath.Path is not null)
244244
{
245-
dllPaths.Add(frameworkPath.Path);
246-
frameworkLocations.Add(frameworkPath.Path);
247-
progressMonitor.LogInfo($"Found .NET Core/Framework DLLs in NuGet packages at {frameworkPath.Path}. Not adding installation directory.");
245+
var versionFolders = new DirectoryInfo(frameworkPath.Path)
246+
.EnumerateDirectories("*", new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive, RecurseSubdirectories = false })
247+
.OrderByDescending(d => d.Name) // TODO: Improve sorting to handle pre-release versions.
248+
.ToArray();
249+
250+
if (versionFolders.Length > 1)
251+
{
252+
var versions = string.Join(", ", versionFolders.Select(d => d.Name));
253+
progressMonitor.LogInfo($"Found multiple .NET Framework DLLs in NuGet packages at {frameworkPath.Path}. Using the latest version ({versionFolders[0].Name}) from: {versions}.");
254+
}
255+
256+
var selectedFrameworkFolder = versionFolders.FirstOrDefault()?.FullName;
257+
if (selectedFrameworkFolder is null)
258+
{
259+
progressMonitor.LogInfo($"Found .NET Framework DLLs in NuGet packages at {frameworkPath.Path}, but no version folder was found.");
260+
selectedFrameworkFolder = frameworkPath.Path;
261+
}
262+
263+
dllPaths.Add(selectedFrameworkFolder);
264+
frameworkLocations.Add(selectedFrameworkFolder);
265+
progressMonitor.LogInfo($"Found .NET Core/Framework DLLs in NuGet packages at {selectedFrameworkFolder}. Not adding installation directory.");
248266

249267
for (var i = frameworkPath.Index + 1; i < packagesInPrioOrder.Length; i++)
250268
{

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
| /avalara.avatax/21.10.0/lib/netstandard20/Avalara.AvaTax.netstandard20.dll |
22
| /microsoft.bcl.asyncinterfaces/6.0.0/lib/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll |
3-
| /microsoft.netcore.app.ref/3.1.0/ref/netcoreapp3.1/System.Data.DataSetExtensions.dll |
4-
| /microsoft.netcore.app.ref/3.1.0/ref/netcoreapp3.1/System.Runtime.InteropServices.WindowsRuntime.dll |
5-
| /microsoft.netcore.app.ref/6.0.13/ref/net6.0/System.Data.dll |
6-
| /microsoft.netcore.app.ref/6.0.13/ref/net6.0/System.Xml.dll |
7-
| /microsoft.netcore.app.ref/6.0.13/ref/net6.0/System.dll |
83
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/Microsoft.CSharp.dll |
94
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/Microsoft.VisualBasic.Core.dll |
105
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/Microsoft.VisualBasic.dll |
@@ -27,6 +22,8 @@
2722
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Console.dll |
2823
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Core.dll |
2924
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Data.Common.dll |
25+
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Data.DataSetExtensions.dll |
26+
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Data.dll |
3027
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Diagnostics.Contracts.dll |
3128
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Diagnostics.Debug.dll |
3229
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Diagnostics.DiagnosticSource.dll |
@@ -161,6 +158,8 @@
161158
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Xml.XPath.dll |
162159
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Xml.XmlDocument.dll |
163160
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Xml.XmlSerializer.dll |
161+
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Xml.dll |
162+
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.dll |
164163
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/WindowsBase.dll |
165164
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/mscorlib.dll |
166165
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/netstandard.dll |

csharp/ql/integration-tests/windows-only/standalone_dependencies/Assemblies.expected

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
| /avalara.avatax/21.10.0/lib/netstandard20/Avalara.AvaTax.netstandard20.dll |
22
| /microsoft.bcl.asyncinterfaces/6.0.0/lib/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll |
3-
| /microsoft.netcore.app.ref/3.1.0/ref/netcoreapp3.1/System.Data.DataSetExtensions.dll |
4-
| /microsoft.netcore.app.ref/3.1.0/ref/netcoreapp3.1/System.Runtime.InteropServices.WindowsRuntime.dll |
5-
| /microsoft.netcore.app.ref/6.0.13/ref/net6.0/System.Data.dll |
6-
| /microsoft.netcore.app.ref/6.0.13/ref/net6.0/System.Xml.dll |
7-
| /microsoft.netcore.app.ref/6.0.13/ref/net6.0/System.dll |
83
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/Microsoft.CSharp.dll |
94
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/Microsoft.VisualBasic.Core.dll |
105
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/Microsoft.Win32.Primitives.dll |
@@ -26,6 +21,8 @@
2621
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Console.dll |
2722
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Core.dll |
2823
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Data.Common.dll |
24+
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Data.DataSetExtensions.dll |
25+
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Data.dll |
2926
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Diagnostics.Contracts.dll |
3027
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Diagnostics.Debug.dll |
3128
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Diagnostics.DiagnosticSource.dll |
@@ -159,6 +156,8 @@
159156
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Xml.XPath.dll |
160157
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Xml.XmlDocument.dll |
161158
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Xml.XmlSerializer.dll |
159+
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.Xml.dll |
160+
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/System.dll |
162161
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/mscorlib.dll |
163162
| /microsoft.netcore.app.ref/7.0.2/ref/net7.0/netstandard.dll |
164163
| /microsoft.windowsdesktop.app.ref/7.0.2/ref/net7.0/Accessibility.dll |

0 commit comments

Comments
 (0)