Skip to content

Commit 4446f42

Browse files
authored
Merge pull request #21684 from michaelnebel/csharp/improve-reachability-checks
C#: Improve BMN feed checking & handling.
2 parents 87c35e6 + 03d70b9 commit 4446f42

19 files changed

Lines changed: 362 additions & 140 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ private string GetRestoreArgs(RestoreSettings restoreSettings)
9595
args += " /p:EnableWindowsTargeting=true";
9696
}
9797

98-
if (restoreSettings.ExtraArgs is not null)
98+
if (restoreSettings.NugetSources is not null)
9999
{
100-
args += $" {restoreSettings.ExtraArgs}";
100+
args += $" {restoreSettings.NugetSources}";
101101
}
102102

103103
return args;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IDotNet
1717
IList<string> GetNugetFeedsFromFolder(string folderPath);
1818
}
1919

20-
public record class RestoreSettings(string File, string PackageDirectory, bool ForceDotnetRefAssemblyFetching, string? ExtraArgs = null, string? PathToNugetConfig = null, bool ForceReevaluation = false, bool TargetWindows = false);
20+
public record class RestoreSettings(string File, string PackageDirectory, bool ForceDotnetRefAssemblyFetching, string? NugetSources = null, string? PathToNugetConfig = null, bool ForceReevaluation = false, bool TargetWindows = false);
2121

2222
public partial record class RestoreResult(bool Success, IList<string> Output)
2323
{
@@ -33,6 +33,9 @@ public partial record class RestoreResult(bool Success, IList<string> Output)
3333
private readonly Lazy<bool> hasNugetNoStablePackageVersionError = new(() => Output.Any(s => s.Contains("NU1103")));
3434
public bool HasNugetNoStablePackageVersionError => hasNugetNoStablePackageVersionError.Value;
3535

36+
private readonly Lazy<bool> hasNugetPackageMissingError = new(() => Output.Any(s => s.Contains("NU1101")));
37+
public bool HasNugetPackageMissingError => hasNugetPackageMissingError.Value;
38+
3639
private static IEnumerable<string> GetFirstGroupOnMatch(Regex regex, IEnumerable<string> lines) =>
3740
lines
3841
.Select(line => regex.Match(line))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal class NugetExeWrapper : IDisposable
3333
/// <summary>
3434
/// Create the package manager for a specified source tree.
3535
/// </summary>
36-
public NugetExeWrapper(FileProvider fileProvider, DependencyDirectory packageDirectory, Semmle.Util.Logging.ILogger logger)
36+
public NugetExeWrapper(FileProvider fileProvider, DependencyDirectory packageDirectory, Semmle.Util.Logging.ILogger logger, Func<bool> useDefaultFeed)
3737
{
3838
this.fileProvider = fileProvider;
3939
this.packageDirectory = packageDirectory;
@@ -43,7 +43,7 @@ public NugetExeWrapper(FileProvider fileProvider, DependencyDirectory packageDir
4343
{
4444
logger.LogInfo($"Found packages.config files, trying to use nuget.exe for package restore");
4545
nugetExe = ResolveNugetExe();
46-
if (HasNoPackageSource())
46+
if (HasNoPackageSource() && useDefaultFeed())
4747
{
4848
// We only modify or add a top level nuget.config file
4949
nugetConfigPath = Path.Combine(fileProvider.SourceDir.FullName, "nuget.config");

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

Lines changed: 255 additions & 133 deletions
Large diffs are not rendered by default.

csharp/ql/integration-tests/all-platforms/standalone_resx/CompilationInfo.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
| All NuGet feeds reachable | 1.0 |
2+
| Failed project restore with missing package error | 0.0 |
23
| Failed project restore with package source error | 0.0 |
4+
| Failed solution restore with missing package error | 0.0 |
35
| Failed solution restore with package source error | 0.0 |
46
| Inherited NuGet feed count | 1.0 |
57
| NuGet feed responsiveness checked | 1.0 |

csharp/ql/integration-tests/all-platforms/standalone_slnx/CompilationInfo.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
| All NuGet feeds reachable | 1.0 |
2+
| Failed project restore with missing package error | 0.0 |
23
| Failed project restore with package source error | 0.0 |
4+
| Failed solution restore with missing package error | 0.0 |
35
| Failed solution restore with package source error | 0.0 |
46
| Inherited NuGet feed count | 1.0 |
57
| NuGet feed responsiveness checked | 1.0 |

csharp/ql/integration-tests/all-platforms/standalone_winforms/CompilationInfo.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
| All NuGet feeds reachable | 1.0 |
2+
| Failed project restore with missing package error | 0.0 |
23
| Failed project restore with package source error | 0.0 |
4+
| Failed solution restore with missing package error | 0.0 |
35
| Failed solution restore with package source error | 0.0 |
46
| Inherited NuGet feed count | 1.0 |
57
| NuGet feed responsiveness checked | 1.0 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test-db/working/packages/newtonsoft.json/13.0.4/lib/net6.0/Newtonsoft.Json.dll:0:0:0:0 | Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import csharp
2+
3+
from Assembly a
4+
where exists(a.getFile().getAbsolutePath().indexOf("newtonsoft.json"))
5+
select a
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
| All NuGet feeds reachable | 1.0 |
2+
| Failed project restore with missing package error | 0.0 |
3+
| Failed project restore with package source error | 0.0 |
4+
| Failed solution restore with missing package error | 0.0 |
5+
| Failed solution restore with package source error | 0.0 |
6+
| Inherited NuGet feed count | 1.0 |
7+
| NuGet feed responsiveness checked | 1.0 |
8+
| Project files on filesystem | 1.0 |
9+
| Reachable fallback NuGet feed count | 1.0 |
10+
| Resolved assembly conflicts | 0.0 |
11+
| Resource extraction enabled | 0.0 |
12+
| Restored .NET framework variants | 1.0 |
13+
| Restored projects through solution files | 0.0 |
14+
| Solution files on filesystem | 0.0 |
15+
| Source files generated | 0.0 |
16+
| Source files on filesystem | 1.0 |
17+
| Successfully restored project files | 1.0 |
18+
| Successfully restored solution files | 0.0 |
19+
| Unresolved references | 0.0 |
20+
| UseWPF set | 0.0 |
21+
| UseWindowsForms set | 0.0 |
22+
| WebView extraction enabled | 1.0 |

0 commit comments

Comments
 (0)