Merge pull request #14273 from tamasvajk/standalone/remove-runtime-nuget-packages

C#: Remove platform-specific runtime nuget packages from the reference list in Standalone
This commit is contained in:
Tamás Vajk
2023-09-21 09:50:10 +02:00
committed by GitHub
2 changed files with 31 additions and 0 deletions

View File

@@ -116,6 +116,7 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
UseReference(filename);
}
RemoveRuntimeNugetPackageReferences();
ResolveConflicts();
// Output the findings
@@ -150,6 +151,33 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
DateTime.Now - startTime);
}
private void RemoveRuntimeNugetPackageReferences()
{
if (!options.UseNuGet)
{
return;
}
var packageFolder = packageDirectory.DirInfo.FullName.ToLowerInvariant();
var runtimePackageNamePrefixes = new[]
{
Path.Combine(packageFolder, "microsoft.netcore.app.runtime"),
Path.Combine(packageFolder, "microsoft.aspnetcore.app.runtime"),
Path.Combine(packageFolder, "microsoft.windowsdesktop.app.runtime"),
};
foreach (var filename in usedReferences.Keys)
{
var lowerFilename = filename.ToLowerInvariant();
if (runtimePackageNamePrefixes.Any(prefix => lowerFilename.StartsWith(prefix)))
{
usedReferences.Remove(filename);
progressMonitor.RemovedReference(filename);
}
}
}
private void GenerateSourceFileFromImplicitUsings()
{
var usings = new HashSet<string>();

View File

@@ -57,6 +57,9 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
public void ResolvedReference(string filename) =>
LogInfo($"Resolved {filename}");
public void RemovedReference(string filename) =>
LogInfo($"Reference {filename} has been removed");
public void Summary(int existingSources, int usedSources, int missingSources,
int references, int unresolvedReferences,
int resolvedConflicts, int totalProjects, int failedProjects,