From bf3677df16434943fde46f691bc96ae0408675a3 Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Fri, 9 Jun 2023 11:10:32 +0200 Subject: [PATCH] C#: Make sure System.Private.CoreLib is added only once as a reference in standalone extraction --- .../BuildAnalysis.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp.Standalone/BuildAnalysis.cs b/csharp/extractor/Semmle.Extraction.CSharp.Standalone/BuildAnalysis.cs index 47bdd3ae568..fc974c7ded6 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.Standalone/BuildAnalysis.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.Standalone/BuildAnalysis.cs @@ -100,6 +100,18 @@ namespace Semmle.BuildAnalyser dllDirNames.Add(runtimeLocation); } + if (options.UseMscorlib) + { + // Add mscorlib.dll or System.Private.CoreLib.dll to the list of DLLs to reference. + var loc = typeof(object).Assembly.Location; + var dir = Path.GetDirectoryName(loc); + if (dir != null) + { + progressMonitor.Log(Util.Logging.Severity.Debug, $"Adding folder {dir} to DLL search path."); + dllDirNames.Add(dir); + } + } + // These files can sometimes prevent `dotnet restore` from working correctly. using (new FileRenamer(sourceDir.GetFiles("global.json", SearchOption.AllDirectories))) using (new FileRenamer(sourceDir.GetFiles("Directory.Build.props", SearchOption.AllDirectories))) @@ -122,11 +134,6 @@ namespace Semmle.BuildAnalyser ResolveConflicts(); - if (options.UseMscorlib) - { - UseReference(typeof(object).Assembly.Location); - } - // Output the findings foreach (var r in usedReferences.Keys) {