dependabot-nuget 0.287.0 → 0.288.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/.gitignore +1 -0
  3. data/helpers/lib/NuGetUpdater/Directory.Build.targets +17 -0
  4. data/helpers/lib/NuGetUpdater/Directory.Packages.props +10 -3
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/DiscoverCommand.cs +7 -3
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/RunCommand.cs +1 -1
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Discover.cs +72 -51
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/AnalyzeWorker.cs +1 -1
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscovery.props +7 -0
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyDiscovery.targets +10 -0
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs +36 -19
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/PackagesConfigDiscovery.cs +6 -2
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/PackagesConfigDiscoveryResult.cs +2 -1
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs +5 -0
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +386 -12
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/WorkspaceDiscoveryResult.cs +1 -1
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +11 -0
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/NuGetUpdater.Core.csproj +7 -2
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Job.cs +23 -0
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +0 -4
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/TargetFrameworkReporter.targets +13 -0
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/LockFileUpdater.cs +1 -0
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +2 -0
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/CollectionExtensions.cs +17 -0
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +57 -4
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathComparer.cs +31 -0
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +30 -2
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTests.cs +50 -0
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTestBase.cs +74 -38
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.PackagesConfig.cs +50 -4
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.Proj.cs +5 -5
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.Project.cs +728 -253
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +322 -78
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/ExpectedDiscoveryResults.cs +2 -6
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs +472 -0
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/MockNuGetPackage.cs +46 -1
  37. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/NuGetUpdater.Core.Test.csproj +0 -1
  38. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +1 -1
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +33 -0
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TemporaryDirectory.cs +3 -2
  41. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +4 -2
  42. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/PathHelperTests.cs +3 -2
  43. data/lib/dependabot/nuget/file_parser.rb +7 -1
  44. data/lib/dependabot/nuget/native_discovery/native_discovery_json_reader.rb +0 -3
  45. data/lib/dependabot/nuget/native_discovery/native_workspace_discovery.rb +7 -10
  46. data/lib/dependabot/nuget/native_helpers.rb +13 -4
  47. metadata +12 -8
  48. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DirectoryPackagesPropsDiscovery.cs +0 -69
  49. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DirectoryPackagesPropsDiscoveryResult.cs +0 -11
  50. data/lib/dependabot/nuget/native_discovery/native_directory_packages_props_discovery.rb +0 -44
@@ -1,3 +1,5 @@
1
+ using System.Collections.Immutable;
2
+ using System.Runtime.InteropServices;
1
3
  using System.Text.Json;
2
4
 
3
5
  using NuGetUpdater.Core.Discover;
@@ -9,12 +11,28 @@ namespace NuGetUpdater.Core.Test.Discover;
9
11
  public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
10
12
  {
11
13
  [Theory]
12
- [InlineData("src/project.csproj")]
13
- [InlineData("src/project.vbproj")]
14
- [InlineData("src/project.fsproj")]
15
- public async Task TestProjectFiles(string projectPath)
14
+ [InlineData("src/project.csproj", true)]
15
+ [InlineData("src/project.csproj", false)]
16
+ [InlineData("src/project.vbproj", true)]
17
+ [InlineData("src/project.vbproj", false)]
18
+ [InlineData("src/project.fsproj", true)]
19
+ [InlineData("src/project.fsproj", false)]
20
+ public async Task TestProjectFiles(string projectPath, bool useDirectDiscovery)
16
21
  {
22
+ var expectedDependencies = new List<Dependency>()
23
+ {
24
+ new Dependency("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true)
25
+ };
26
+ if (useDirectDiscovery && Path.GetExtension(projectPath)! == ".fsproj")
27
+ {
28
+ // this package ships with the SDK and is automatically added for F# projects but should be manually added here to make the test consistent
29
+ // only direct package discovery finds this, though
30
+ expectedDependencies.Add(new Dependency("FSharp.Core", "9.0.100", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true));
31
+ }
32
+
33
+ var experimentsManager = new ExperimentsManager() { UseDirectDiscovery = useDirectDiscovery };
17
34
  await TestDiscoveryAsync(
35
+ experimentsManager: experimentsManager,
18
36
  packages:
19
37
  [
20
38
  MockNuGetPackage.CreateSimplePackage("Some.Package", "9.0.1", "net8.0"),
@@ -43,12 +61,7 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
43
61
  {
44
62
  FilePath = Path.GetFileName(projectPath),
45
63
  TargetFrameworks = ["net8.0"],
46
- ReferencedProjectPaths = [],
47
- ExpectedDependencyCount = 2,
48
- Dependencies = [
49
- new("Microsoft.NET.Sdk", null, DependencyType.MSBuildSdk),
50
- new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true)
51
- ],
64
+ Dependencies = expectedDependencies.ToImmutableArray(),
52
65
  Properties = [
53
66
  new("SomePackageVersion", "9.0.1", projectPath),
54
67
  new("TargetFramework", "net8.0", projectPath),
@@ -59,10 +72,60 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
59
72
  );
60
73
  }
61
74
 
62
- [Fact]
63
- public async Task TestDependencyWithTrailingSpacesInAttribute()
75
+ [Theory]
76
+ [InlineData(true)]
77
+ [InlineData(false)]
78
+ public async Task FindDependenciesFromSDKProjectsWithDesktopTFM(bool useDirectDiscovery)
64
79
  {
80
+ var experimentsManager = new ExperimentsManager() { UseDirectDiscovery = useDirectDiscovery };
65
81
  await TestDiscoveryAsync(
82
+ experimentsManager: experimentsManager,
83
+ packages:
84
+ [
85
+ MockNuGetPackage.CreateSimplePackage("Some.Package", "1.2.3", "net472"),
86
+ ],
87
+ workspacePath: "src",
88
+ files:
89
+ [
90
+ ("src/project.csproj", """
91
+ <Project Sdk="Microsoft.NET.Sdk">
92
+ <PropertyGroup>
93
+ <TargetFramework>net472</TargetFramework>
94
+ </PropertyGroup>
95
+ <ItemGroup>
96
+ <PackageReference Include="Some.Package" Version="1.2.3" />
97
+ </ItemGroup>
98
+ </Project>
99
+ """)
100
+ ],
101
+ expectedResult: new()
102
+ {
103
+ Path = "src",
104
+ Projects = [
105
+ new()
106
+ {
107
+ FilePath = "project.csproj",
108
+ TargetFrameworks = ["net472"],
109
+ Dependencies = [
110
+ new("Some.Package", "1.2.3", DependencyType.PackageReference, TargetFrameworks: ["net472"], IsDirect: true)
111
+ ],
112
+ Properties = [
113
+ new("TargetFramework", "net472", "src/project.csproj"),
114
+ ]
115
+ }
116
+ ]
117
+ }
118
+ );
119
+ }
120
+
121
+ [Theory]
122
+ [InlineData(true)]
123
+ [InlineData(false)]
124
+ public async Task TestDependencyWithTrailingSpacesInAttribute(bool useDirectDiscovery)
125
+ {
126
+ var experimentsManager = new ExperimentsManager() { UseDirectDiscovery = useDirectDiscovery };
127
+ await TestDiscoveryAsync(
128
+ experimentsManager: experimentsManager,
66
129
  packages:
67
130
  [
68
131
  MockNuGetPackage.CreateSimplePackage("Some.Package", "9.0.1", "net8.0"),
@@ -91,10 +154,7 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
91
154
  {
92
155
  FilePath = "project.csproj",
93
156
  TargetFrameworks = ["net8.0"],
94
- ReferencedProjectPaths = [],
95
- ExpectedDependencyCount = 2,
96
157
  Dependencies = [
97
- new("Microsoft.NET.Sdk", null, DependencyType.MSBuildSdk),
98
158
  new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true)
99
159
  ],
100
160
  Properties = [
@@ -116,6 +176,7 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
116
176
  MockNuGetPackage.CreateSimplePackage("Some.Package", "9.0.1", "net8.0"),
117
177
  MockNuGetPackage.CreateSimplePackage("Some.Package2", "9.0.1", "net8.0"),
118
178
  ],
179
+ experimentsManager: new ExperimentsManager() { UseDirectDiscovery = true },
119
180
  workspacePath: "src",
120
181
  files: new[]
121
182
  {
@@ -141,9 +202,7 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
141
202
  FilePath = "project.csproj",
142
203
  TargetFrameworks = ["net8.0"],
143
204
  ReferencedProjectPaths = [],
144
- ExpectedDependencyCount = 3,
145
205
  Dependencies = [
146
- new("Microsoft.NET.Sdk", null, DependencyType.MSBuildSdk),
147
206
  new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true),
148
207
  new("Some.Package2", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true),
149
208
  ],
@@ -166,6 +225,7 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
166
225
  MockNuGetPackage.CreateSimplePackage("Some.Package", "9.0.1", "net8.0"),
167
226
  MockNuGetPackage.CreateSimplePackage("Some.Package2", "9.0.1", "net8.0"),
168
227
  ],
228
+ experimentsManager: new ExperimentsManager() { UseDirectDiscovery = true },
169
229
  workspacePath: "src",
170
230
  files: new[]
171
231
  {
@@ -191,9 +251,7 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
191
251
  FilePath = "project.csproj",
192
252
  TargetFrameworks = ["net8.0"],
193
253
  ReferencedProjectPaths = [],
194
- ExpectedDependencyCount = 3,
195
254
  Dependencies = [
196
- new("Microsoft.NET.Sdk", null, DependencyType.MSBuildSdk),
197
255
  new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true),
198
256
  new("Some.Package2", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true),
199
257
  ],
@@ -207,10 +265,14 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
207
265
  );
208
266
  }
209
267
 
210
- [Fact]
211
- public async Task TestPackageConfig()
268
+ [Theory]
269
+ [InlineData(true)]
270
+ [InlineData(false)]
271
+ public async Task TestPackageConfig(bool useDirectDiscovery)
212
272
  {
273
+ var experimentsManager = new ExperimentsManager() { UseDirectDiscovery = useDirectDiscovery };
213
274
  await TestDiscoveryAsync(
275
+ experimentsManager: experimentsManager,
214
276
  packages:
215
277
  [
216
278
  MockNuGetPackage.CreateSimplePackage("Some.Package", "7.0.1", "net45"),
@@ -250,25 +312,82 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
250
312
  {
251
313
  FilePath = "project.csproj",
252
314
  TargetFrameworks = ["net45"],
253
- ReferencedProjectPaths = [],
254
- ExpectedDependencyCount = 2,
255
315
  Dependencies = [
256
- new("Microsoft.NETFramework.ReferenceAssemblies", "1.0.3", DependencyType.Unknown, TargetFrameworks: ["net45"], IsTransitive: true),
257
316
  new("Some.Package", "7.0.1", DependencyType.PackagesConfig, TargetFrameworks: ["net45"]),
258
317
  ],
318
+ Properties = []
319
+ }
320
+ ]
321
+ }
322
+ );
323
+ }
324
+
325
+ [Fact]
326
+ public async Task TestProps_DirectDiscovery()
327
+ {
328
+ await TestDiscoveryAsync(
329
+ experimentsManager: new ExperimentsManager() { UseDirectDiscovery = true },
330
+ packages:
331
+ [
332
+ MockNuGetPackage.CreateSimplePackage("Some.Package", "9.0.1", "net8.0"),
333
+ ],
334
+ workspacePath: "src",
335
+ files: new[]
336
+ {
337
+ ("src/project.csproj", """
338
+ <Project Sdk="Microsoft.NET.Sdk">
339
+ <PropertyGroup>
340
+ <TargetFramework>net8.0</TargetFramework>
341
+ </PropertyGroup>
342
+
343
+ <ItemGroup>
344
+ <PackageReference Include="Some.Package" />
345
+ </ItemGroup>
346
+ </Project>
347
+ """),
348
+ ("Directory.Build.props", "<Project />"),
349
+ ("Directory.Packages.props", """
350
+ <Project>
351
+ <PropertyGroup>
352
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
353
+ <SomePackageVersion>9.0.1</SomePackageVersion>
354
+ </PropertyGroup>
355
+
356
+ <ItemGroup>
357
+ <PackageVersion Include="Some.Package" Version="$(SomePackageVersion)" />
358
+ </ItemGroup>
359
+ </Project>
360
+ """)
361
+ },
362
+ expectedResult: new()
363
+ {
364
+ Path = "src",
365
+ Projects = [
366
+ new()
367
+ {
368
+ FilePath = "project.csproj",
369
+ TargetFrameworks = ["net8.0"],
370
+ Dependencies = [
371
+ new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true)
372
+ ],
259
373
  Properties = [
260
- new("TargetFrameworkVersion", "v4.5", "src/project.csproj"),
374
+ new("TargetFramework", "net8.0", "src/project.csproj")
261
375
  ]
262
376
  }
377
+ ],
378
+ ImportedFiles = [
379
+ "Directory.Build.props",
380
+ "Directory.Packages.props",
263
381
  ]
264
382
  }
265
383
  );
266
384
  }
267
385
 
268
386
  [Fact]
269
- public async Task TestProps()
387
+ public async Task TestProps_NoDirectDiscovery()
270
388
  {
271
389
  await TestDiscoveryAsync(
390
+ experimentsManager: new ExperimentsManager() { UseDirectDiscovery = false },
272
391
  packages:
273
392
  [
274
393
  MockNuGetPackage.CreateSimplePackage("Some.Package", "9.0.1", "net8.0"),
@@ -304,44 +423,38 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
304
423
  expectedResult: new()
305
424
  {
306
425
  Path = "src",
307
- ExpectedProjectCount = 2,
308
426
  Projects = [
309
427
  new()
310
428
  {
311
429
  FilePath = "project.csproj",
312
430
  TargetFrameworks = ["net8.0"],
313
- ReferencedProjectPaths = [],
314
- ExpectedDependencyCount = 2,
315
431
  Dependencies = [
316
- new("Microsoft.NET.Sdk", null, DependencyType.MSBuildSdk),
317
432
  new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true)
318
433
  ],
319
434
  Properties = [
320
435
  new("ManagePackageVersionsCentrally", "true", "Directory.Packages.props"),
321
436
  new("SomePackageVersion", "9.0.1", "Directory.Packages.props"),
322
- new("TargetFramework", "net8.0", "src/project.csproj"),
437
+ new("TargetFramework", "net8.0", "src/project.csproj")
323
438
  ]
324
439
  }
325
440
  ],
326
- DirectoryPackagesProps = new()
327
- {
328
- FilePath = "../Directory.Packages.props",
329
- Dependencies = [
330
- new("Some.Package", "9.0.1", DependencyType.PackageVersion, IsDirect: true)
331
- ],
332
- }
441
+ ImportedFiles = [
442
+ "Directory.Build.props",
443
+ "Directory.Packages.props",
444
+ ]
333
445
  }
334
446
  );
335
447
  }
336
448
 
337
449
  [Fact]
338
- public async Task TestRepo()
450
+ public async Task TestRepo_DirectDiscovery()
339
451
  {
340
452
  var solutionPath = "solution.sln";
341
453
  await TestDiscoveryAsync(
454
+ experimentsManager: new ExperimentsManager() { UseDirectDiscovery = true },
342
455
  packages:
343
456
  [
344
- MockNuGetPackage.CreateSimplePackage("Some.Package", "9.0.1", "net8.0"),
457
+ MockNuGetPackage.CreateSimplePackage("Some.Package", "9.0.1", "net7.0"),
345
458
  ],
346
459
  workspacePath: "",
347
460
  files: new[]
@@ -429,31 +542,24 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
429
542
  expectedResult: new()
430
543
  {
431
544
  Path = "",
432
- ExpectedProjectCount = 2,
433
545
  Projects = [
434
546
  new()
435
547
  {
436
548
  FilePath = "src/project.csproj",
437
549
  TargetFrameworks = ["net7.0", "net8.0"],
438
- ExpectedDependencyCount = 2,
439
550
  Dependencies = [
440
- new("Microsoft.NET.Sdk", null, DependencyType.MSBuildSdk),
441
- new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net7.0", "net8.0"], IsDirect: true)
551
+ new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net7.0"], IsDirect: true),
552
+ new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true),
442
553
  ],
443
554
  Properties = [
444
- new("ManagePackageVersionsCentrally", "true", "Directory.Packages.props"),
445
- new("SomePackageVersion", "9.0.1", "Directory.Packages.props"),
446
- new("TargetFrameworks", "net7.0;net8.0", "src/project.csproj"),
555
+ new("TargetFrameworks", "net7.0;net8.0", "src/project.csproj")
447
556
  ]
448
557
  }
449
558
  ],
450
- DirectoryPackagesProps = new()
451
- {
452
- FilePath = "Directory.Packages.props",
453
- Dependencies = [
454
- new("Some.Package", "9.0.1", DependencyType.PackageVersion, IsDirect: true)
455
- ],
456
- },
559
+ ImportedFiles = [
560
+ "Directory.Build.props",
561
+ "Directory.Packages.props",
562
+ ],
457
563
  GlobalJson = new()
458
564
  {
459
565
  FilePath = "global.json",
@@ -538,15 +644,12 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
538
644
  expectedResult: new()
539
645
  {
540
646
  Path = "",
541
- ExpectedProjectCount = 2,
542
647
  Projects = [
543
648
  new()
544
649
  {
545
650
  FilePath = "src/project.csproj",
546
651
  TargetFrameworks = ["net7.0", "net8.0"],
547
- ExpectedDependencyCount = 2,
548
652
  Dependencies = [
549
- new("Microsoft.NET.Sdk", null, DependencyType.MSBuildSdk),
550
653
  new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net7.0", "net8.0"], IsDirect: true)
551
654
  ],
552
655
  Properties = [
@@ -556,13 +659,10 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
556
659
  ]
557
660
  }
558
661
  ],
559
- DirectoryPackagesProps = new()
560
- {
561
- FilePath = "Directory.Packages.props",
562
- Dependencies = [
563
- new("Some.Package", "9.0.1", DependencyType.PackageVersion, IsDirect: true)
564
- ],
565
- },
662
+ ImportedFiles = [
663
+ "Directory.Build.props",
664
+ "Directory.Packages.props"
665
+ ]
566
666
  }
567
667
  );
568
668
  }
@@ -615,15 +715,12 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
615
715
  expectedResult: new()
616
716
  {
617
717
  Path = "",
618
- ExpectedProjectCount = 2,
619
718
  Projects = [
620
719
  new()
621
720
  {
622
721
  FilePath = "src/project.csproj",
623
722
  TargetFrameworks = ["net7.0", "net8.0"],
624
- ExpectedDependencyCount = 2,
625
723
  Dependencies = [
626
- new("Microsoft.NET.Sdk", null, DependencyType.MSBuildSdk),
627
724
  new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net7.0", "net8.0"], IsDirect: true)
628
725
  ],
629
726
  Properties = [
@@ -633,21 +730,158 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
633
730
  ]
634
731
  }
635
732
  ],
636
- DirectoryPackagesProps = new()
733
+ ImportedFiles = [
734
+ "Directory.Build.props",
735
+ "Directory.Packages.props"
736
+ ]
737
+ }
738
+ );
739
+ }
740
+
741
+ [Fact]
742
+ public async Task TestRepo_NoDirectDiscovery()
743
+ {
744
+ var solutionPath = "solution.sln";
745
+ await TestDiscoveryAsync(
746
+ experimentsManager: new ExperimentsManager() { UseDirectDiscovery = false },
747
+ packages:
748
+ [
749
+ MockNuGetPackage.CreateSimplePackage("Some.Package", "9.0.1", "net7.0"),
750
+ ],
751
+ workspacePath: "",
752
+ files: new[]
753
+ {
754
+ ("src/project.csproj", """
755
+ <Project Sdk="Microsoft.NET.Sdk">
756
+ <PropertyGroup>
757
+ <TargetFrameworks>net7.0;net8.0</TargetFrameworks>
758
+ </PropertyGroup>
759
+
760
+ <ItemGroup>
761
+ <PackageReference Include="Some.Package" />
762
+ </ItemGroup>
763
+ </Project>
764
+ """),
765
+ ("Directory.Build.props", "<Project />"),
766
+ ("Directory.Packages.props", """
767
+ <Project>
768
+ <PropertyGroup>
769
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
770
+ <SomePackageVersion>9.0.1</SomePackageVersion>
771
+ </PropertyGroup>
772
+
773
+ <ItemGroup>
774
+ <PackageVersion Include="Some.Package" Version="$(SomePackageVersion)" />
775
+ </ItemGroup>
776
+ </Project>
777
+ """),
778
+ (solutionPath, """
779
+ Microsoft Visual Studio Solution File, Format Version 12.00
780
+ # Visual Studio 14
781
+ VisualStudioVersion = 14.0.22705.0
782
+ MinimumVisualStudioVersion = 10.0.40219.1
783
+ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "project", ".\src\project.csproj", "{782E0C0A-10D3-444D-9640-263D03D2B20C}"
784
+ EndProject
785
+ Global
786
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
787
+ Debug|Any CPU = Debug|Any CPU
788
+ Release|Any CPU = Release|Any CPU
789
+ EndGlobalSection
790
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
791
+ {782E0C0A-10D3-444D-9640-263D03D2B20C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
792
+ {782E0C0A-10D3-444D-9640-263D03D2B20C}.Debug|Any CPU.Build.0 = Debug|Any CPU
793
+ {782E0C0A-10D3-444D-9640-263D03D2B20C}.Release|Any CPU.ActiveCfg = Release|Any CPU
794
+ {782E0C0A-10D3-444D-9640-263D03D2B20C}.Release|Any CPU.Build.0 = Release|Any CPU
795
+ EndGlobalSection
796
+ GlobalSection(SolutionProperties) = preSolution
797
+ HideSolutionNode = FALSE
798
+ EndGlobalSection
799
+ EndGlobal
800
+ """),
801
+ ("global.json", """
802
+ {
803
+ "sdk": {
804
+ "version": "6.0.405",
805
+ "rollForward": "latestPatch"
806
+ },
807
+ "msbuild-sdks": {
808
+ "My.Custom.Sdk": "5.0.0",
809
+ "My.Other.Sdk": "1.0.0-beta"
810
+ }
811
+ }
812
+ """),
813
+ (".config/dotnet-tools.json", """
814
+ {
815
+ "version": 1,
816
+ "isRoot": true,
817
+ "tools": {
818
+ "microsoft.botsay": {
819
+ "version": "1.0.0",
820
+ "commands": [
821
+ "botsay"
822
+ ]
823
+ },
824
+ "dotnetsay": {
825
+ "version": "2.1.3",
826
+ "commands": [
827
+ "dotnetsay"
828
+ ]
829
+ }
830
+ }
831
+ }
832
+ """),
833
+ },
834
+ expectedResult: new()
835
+ {
836
+ Path = "",
837
+ Projects = [
838
+ new()
839
+ {
840
+ FilePath = "src/project.csproj",
841
+ TargetFrameworks = ["net7.0", "net8.0"],
842
+ Dependencies = [
843
+ new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net7.0", "net8.0"], IsDirect: true),
844
+ ],
845
+ Properties = [
846
+ new("ManagePackageVersionsCentrally", "true", "Directory.Packages.props"),
847
+ new("SomePackageVersion", "9.0.1", "Directory.Packages.props"),
848
+ new("TargetFrameworks", "net7.0;net8.0", "src/project.csproj")
849
+ ]
850
+ }
851
+ ],
852
+ ImportedFiles = [
853
+ "Directory.Build.props",
854
+ "Directory.Packages.props",
855
+ ],
856
+ GlobalJson = new()
637
857
  {
638
- FilePath = "Directory.Packages.props",
858
+ FilePath = "global.json",
639
859
  Dependencies = [
640
- new("Some.Package", "9.0.1", DependencyType.PackageVersion, IsDirect: true)
641
- ],
860
+ new("Microsoft.NET.Sdk", "6.0.405", DependencyType.MSBuildSdk),
861
+ new("My.Custom.Sdk", "5.0.0", DependencyType.MSBuildSdk),
862
+ new("My.Other.Sdk", "1.0.0-beta", DependencyType.MSBuildSdk),
863
+ ]
642
864
  },
865
+ DotNetToolsJson = new()
866
+ {
867
+ FilePath = ".config/dotnet-tools.json",
868
+ Dependencies = [
869
+ new("microsoft.botsay", "1.0.0", DependencyType.DotNetTool),
870
+ new("dotnetsay", "2.1.3", DependencyType.DotNetTool),
871
+ ]
872
+ }
643
873
  }
644
874
  );
645
875
  }
646
876
 
647
- [Fact]
648
- public async Task NonSupportedProjectExtensionsAreSkipped()
877
+ [Theory]
878
+ [InlineData(true)]
879
+ [InlineData(false)]
880
+ public async Task NonSupportedProjectExtensionsAreSkipped(bool useDirectDiscovery)
649
881
  {
882
+ var experimentsManager = new ExperimentsManager() { UseDirectDiscovery = useDirectDiscovery };
650
883
  await TestDiscoveryAsync(
884
+ experimentsManager: experimentsManager,
651
885
  packages:
652
886
  [
653
887
  MockNuGetPackage.CreateSimplePackage("Some.Package", "1.0.0", "net8.0"),
@@ -712,10 +946,7 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
712
946
  {
713
947
  FilePath = "src/supported.csproj",
714
948
  TargetFrameworks = ["net8.0"],
715
- ReferencedProjectPaths = [],
716
- ExpectedDependencyCount = 2,
717
949
  Dependencies = [
718
- new("Microsoft.NET.Sdk", null, DependencyType.MSBuildSdk),
719
950
  new("Some.Package", "1.0.0", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true)
720
951
  ],
721
952
  Properties = [
@@ -756,8 +987,10 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
756
987
  Assert.Equal("<some package feed>", errorDetails.GetString());
757
988
  }
758
989
 
759
- [Fact]
760
- public async Task ReportsPrivateSourceAuthenticationFailure()
990
+ [Theory]
991
+ [InlineData(true)]
992
+ [InlineData(false)]
993
+ public async Task ReportsPrivateSourceAuthenticationFailure(bool useDirectDiscovery)
761
994
  {
762
995
  static (int, string) TestHttpHandler(string uriString)
763
996
  {
@@ -789,8 +1022,19 @@ public partial class DiscoveryWorkerTests : DiscoveryWorkerTestBase
789
1022
  _ => (401, "{}"),
790
1023
  };
791
1024
  }
1025
+ // override various nuget locations
1026
+ using var tempDir = new TemporaryDirectory();
1027
+ using var _ = new TemporaryEnvironment(
1028
+ [
1029
+ ("NUGET_PACKAGES", Path.Combine(tempDir.DirectoryPath, "NUGET_PACKAGES")),
1030
+ ("NUGET_HTTP_CACHE_PATH", Path.Combine(tempDir.DirectoryPath, "NUGET_HTTP_CACHE_PATH")),
1031
+ ("NUGET_SCRATCH", Path.Combine(tempDir.DirectoryPath, "NUGET_SCRATCH")),
1032
+ ("NUGET_PLUGINS_CACHE_PATH", Path.Combine(tempDir.DirectoryPath, "NUGET_PLUGINS_CACHE_PATH")),
1033
+ ]);
792
1034
  using var http = TestHttpServer.CreateTestStringServer(TestHttpHandler);
1035
+ var experimentsManager = new ExperimentsManager() { UseDirectDiscovery = useDirectDiscovery };
793
1036
  await TestDiscoveryAsync(
1037
+ experimentsManager: experimentsManager,
794
1038
  workspacePath: "",
795
1039
  files:
796
1040
  [
@@ -9,22 +9,18 @@ public record ExpectedWorkspaceDiscoveryResult : NativeResult
9
9
  public required string Path { get; init; }
10
10
  public bool IsSuccess { get; init; } = true;
11
11
  public ImmutableArray<ExpectedSdkProjectDiscoveryResult> Projects { get; init; }
12
+ public ImmutableArray<string> ImportedFiles { get; init; } = [];
12
13
  public int? ExpectedProjectCount { get; init; }
13
- public ExpectedDirectoryPackagesPropsDiscovertyResult? DirectoryPackagesProps { get; init; }
14
14
  public ExpectedDependencyDiscoveryResult? GlobalJson { get; init; }
15
15
  public ExpectedDependencyDiscoveryResult? DotNetToolsJson { get; init; }
16
16
  }
17
17
 
18
- public record ExpectedDirectoryPackagesPropsDiscovertyResult : ExpectedDependencyDiscoveryResult
19
- {
20
- public bool IsTransitivePinningEnabled { get; init; }
21
- }
22
-
23
18
  public record ExpectedSdkProjectDiscoveryResult : ExpectedDependencyDiscoveryResult
24
19
  {
25
20
  public ImmutableArray<Property> Properties { get; init; } = [];
26
21
  public ImmutableArray<string> TargetFrameworks { get; init; } = [];
27
22
  public ImmutableArray<string> ReferencedProjectPaths { get; init; } = [];
23
+ public ImmutableArray<string>? ImportedFiles { get; init; } = null;
28
24
  }
29
25
 
30
26
  public record ExpectedDependencyDiscoveryResult : IDiscoveryResultWithDependencies