Skip to content

Commit faa63dd

Browse files
authored
Merge pull request #14994 from tamasvajk/standalone/framework-assembly-reshuffle
C#: Only consider latest version of dotnet framework flavors
2 parents 49c188e + efa7408 commit faa63dd

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,21 +230,44 @@ private void RemoveNugetAnalyzerReferences()
230230
}
231231
}
232232

233+
private void SelectNewestFrameworkPath(string frameworkPath, string frameworkType, ISet<string> dllPaths, ISet<string> frameworkLocations)
234+
{
235+
var versionFolders = new DirectoryInfo(frameworkPath)
236+
.EnumerateDirectories("*", new EnumerationOptions { MatchCasing = MatchCasing.CaseInsensitive, RecurseSubdirectories = false })
237+
.OrderByDescending(d => d.Name) // TODO: Improve sorting to handle pre-release versions.
238+
.ToArray();
239+
240+
if (versionFolders.Length > 1)
241+
{
242+
var versions = string.Join(", ", versionFolders.Select(d => d.Name));
243+
progressMonitor.LogInfo($"Found multiple {frameworkType} DLLs in NuGet packages at {frameworkPath}. Using the latest version ({versionFolders[0].Name}) from: {versions}.");
244+
}
245+
246+
var selectedFrameworkFolder = versionFolders.FirstOrDefault()?.FullName;
247+
if (selectedFrameworkFolder is null)
248+
{
249+
progressMonitor.LogInfo($"Found {frameworkType} DLLs in NuGet packages at {frameworkPath}, but no version folder was found.");
250+
selectedFrameworkFolder = frameworkPath;
251+
}
252+
253+
dllPaths.Add(selectedFrameworkFolder);
254+
frameworkLocations.Add(selectedFrameworkFolder);
255+
progressMonitor.LogInfo($"Found {frameworkType} DLLs in NuGet packages at {selectedFrameworkFolder}. Not adding installation directory.");
256+
}
257+
233258
private void AddNetFrameworkDlls(ISet<string> dllPaths, ISet<string> frameworkLocations)
234259
{
235260
// Multiple dotnet framework packages could be present.
236261
// The order of the packages is important, we're adding the first one that is present in the nuget cache.
237262
var packagesInPrioOrder = FrameworkPackageNames.NetFrameworks;
238263

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

243268
if (frameworkPath.Path is not null)
244269
{
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.");
270+
SelectNewestFrameworkPath(frameworkPath.Path, ".NET Framework", dllPaths, frameworkLocations);
248271

249272
for (var i = frameworkPath.Index + 1; i < packagesInPrioOrder.Length; i++)
250273
{
@@ -308,9 +331,7 @@ private void AddAspNetCoreFrameworkDlls(ISet<string> dllPaths, ISet<string> fram
308331
// First try to find ASP.NET Core assemblies in the NuGet packages
309332
if (GetPackageDirectory(FrameworkPackageNames.AspNetCoreFramework) is string aspNetCorePackage)
310333
{
311-
progressMonitor.LogInfo($"Found ASP.NET Core in NuGet packages. Not adding installation directory.");
312-
dllPaths.Add(aspNetCorePackage);
313-
frameworkLocations.Add(aspNetCorePackage);
334+
SelectNewestFrameworkPath(aspNetCorePackage, "ASP.NET Core", dllPaths, frameworkLocations);
314335
return;
315336
}
316337

@@ -326,9 +347,7 @@ private void AddMicrosoftWindowsDesktopDlls(ISet<string> dllPaths, ISet<string>
326347
{
327348
if (GetPackageDirectory(FrameworkPackageNames.WindowsDesktopFramework) is string windowsDesktopApp)
328349
{
329-
progressMonitor.LogInfo($"Found Windows Desktop App in NuGet packages.");
330-
dllPaths.Add(windowsDesktopApp);
331-
frameworkLocations.Add(windowsDesktopApp);
350+
SelectNewestFrameworkPath(windowsDesktopApp, "Windows Desktop App", dllPaths, frameworkLocations);
332351
}
333352
}
334353

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)