dependabot-nuget 0.288.0 → 0.289.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/Directory.Packages.props +19 -17
  3. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Packaging/NuGet.Packaging.csproj +0 -1
  4. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Analyze.cs +3 -1
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Discover.cs +23 -3
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/AnalyzeWorker.cs +30 -15
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/CompatabilityChecker.cs +1 -1
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/RequirementArrayConverter.cs +39 -0
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/VersionFinder.cs +1 -1
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Clone/ShellGitCommandHandler.cs +1 -1
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs +60 -66
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DotNetToolsJsonDiscovery.cs +2 -2
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/GlobalJsonDiscovery.cs +2 -2
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/PackagesConfigDiscovery.cs +11 -3
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/PackagesConfigDiscoveryResult.cs +1 -0
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs +2 -4
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +54 -11
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/WorkspaceDiscoveryResult.cs +0 -1
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +1 -2
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +1 -1
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/CompatabilityChecker.cs +2 -2
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +43 -54
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs +13 -43
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +4 -4
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +5 -5
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/LockFileUpdater.cs +2 -10
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +38 -33
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +12 -11
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +16 -12
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ConsoleLogger.cs +1 -1
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/DependencyConflictResolver.cs +19 -19
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ILogger.cs +11 -1
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +18 -17
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/NuGetHelper.cs +1 -17
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +17 -9
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProjectHelper.cs +96 -0
  37. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTests.cs +87 -5
  38. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTestBase.cs +2 -5
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.PackagesConfig.cs +16 -0
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.Proj.cs +6 -0
  41. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.Project.cs +147 -36
  42. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +184 -48
  43. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/ExpectedDiscoveryResults.cs +5 -5
  44. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs +32 -10
  45. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +400 -76
  46. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +2 -2
  47. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatedDependencyListTests.cs +60 -2
  48. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestLogger.cs +1 -1
  49. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/BindingRedirectsTests.cs +1 -1
  50. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +4 -2
  51. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs +40 -0
  52. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +1 -1
  53. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/AssertEx.cs +1 -1
  54. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/LinuxOnlyAttribute.cs +12 -0
  55. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +8 -5
  56. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/PathHelperTests.cs +47 -2
  57. data/lib/dependabot/nuget/analysis/analysis_json_reader.rb +3 -1
  58. data/lib/dependabot/nuget/file_fetcher.rb +12 -393
  59. data/lib/dependabot/nuget/file_parser.rb +23 -60
  60. data/lib/dependabot/nuget/file_updater.rb +21 -16
  61. data/lib/dependabot/nuget/native_discovery/native_dependency_file_discovery.rb +2 -9
  62. data/lib/dependabot/nuget/native_discovery/native_discovery_json_reader.rb +183 -77
  63. data/lib/dependabot/nuget/native_discovery/native_project_discovery.rb +25 -3
  64. data/lib/dependabot/nuget/native_discovery/native_workspace_discovery.rb +1 -8
  65. data/lib/dependabot/nuget/native_update_checker/native_update_checker.rb +17 -4
  66. metadata +8 -9
  67. data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Packages.props +0 -29
  68. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/RequirementConverter.cs +0 -17
  69. data/lib/dependabot/nuget/file_fetcher/import_paths_finder.rb +0 -73
  70. data/lib/dependabot/nuget/file_fetcher/sln_project_paths_finder.rb +0 -60
@@ -30,7 +30,7 @@ internal static class PackageReferenceUpdater
30
30
  ILogger logger)
31
31
  {
32
32
  // PackageReference project; modify the XML directly
33
- logger.Log(" Running 'PackageReference' project direct XML update");
33
+ logger.Info(" Running 'PackageReference' project direct XML update");
34
34
 
35
35
  (ImmutableArray<ProjectBuildFile> buildFiles, string[] tfms) = await MSBuildHelper.LoadBuildFilesAndTargetFrameworksAsync(repoRootPath, projectPath);
36
36
 
@@ -61,6 +61,11 @@ internal static class PackageReferenceUpdater
61
61
  }
62
62
  else
63
63
  {
64
+ if (peerDependencies is null)
65
+ {
66
+ return;
67
+ }
68
+
64
69
  await UpdateDependencyWithConflictResolution(repoRootPath, buildFiles, tfms, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive, peerDependencies, logger);
65
70
  }
66
71
 
@@ -105,7 +110,7 @@ internal static class PackageReferenceUpdater
105
110
  var resolvedDependencies = await MSBuildHelper.ResolveDependencyConflicts(repoRootPath, projectFile.Path, tfm, topLevelDependencies, dependenciesToUpdate, logger);
106
111
  if (resolvedDependencies is null)
107
112
  {
108
- logger.Log($" Unable to resolve dependency conflicts for {projectFile.Path}.");
113
+ logger.Warn($" Unable to resolve dependency conflicts for {projectFile.Path}.");
109
114
  continue;
110
115
  }
111
116
 
@@ -184,14 +189,14 @@ internal static class PackageReferenceUpdater
184
189
  // Skip updating the project if the dependency does not exist in the graph
185
190
  if (!packageFound)
186
191
  {
187
- logger.Log($" Package [{dependencyName}] Does not exist as a dependency in [{projectPath}].");
192
+ logger.Info($" Package [{dependencyName}] Does not exist as a dependency in [{projectPath}].");
188
193
  return false;
189
194
  }
190
195
 
191
196
  // Skip updating the project if the dependency version meets or exceeds the newDependencyVersion
192
197
  if (!needsUpdate)
193
198
  {
194
- logger.Log($" Package [{dependencyName}] already meets the requested dependency version in [{projectPath}].");
199
+ logger.Info($" Package [{dependencyName}] already meets the requested dependency version in [{projectPath}].");
195
200
  return false;
196
201
  }
197
202
 
@@ -242,7 +247,7 @@ internal static class PackageReferenceUpdater
242
247
  a.Value.Equals(dependencyName, StringComparison.OrdinalIgnoreCase)))
243
248
  .FirstOrDefault();
244
249
 
245
- logger.Log($" Pinning [{dependencyName}/{newDependencyVersion}] as a package version.");
250
+ logger.Info($" Pinning [{dependencyName}/{newDependencyVersion}] as a package version.");
246
251
 
247
252
  var lastPackageVersion = directoryPackages.ItemNodes
248
253
  .Where(e => e.Name.Equals("PackageVersion", StringComparison.OrdinalIgnoreCase))
@@ -250,7 +255,7 @@ internal static class PackageReferenceUpdater
250
255
 
251
256
  if (lastPackageVersion is null)
252
257
  {
253
- logger.Log($" Transitive dependency [{dependencyName}/{newDependencyVersion}] was not pinned.");
258
+ logger.Info($" Transitive dependency [{dependencyName}/{newDependencyVersion}] was not pinned.");
254
259
  return;
255
260
  }
256
261
 
@@ -260,7 +265,7 @@ internal static class PackageReferenceUpdater
260
265
  if (existingPackageVersionElement is null)
261
266
  {
262
267
  // need to add a new entry
263
- logger.Log(" New PackageVersion element added.");
268
+ logger.Info(" New PackageVersion element added.");
264
269
  var leadingTrivia = lastPackageVersion.AsNode.GetLeadingTrivia();
265
270
  var packageVersionElement = XmlExtensions.CreateSingleLineXmlElementSyntax("PackageVersion", new SyntaxList<SyntaxNode>(leadingTrivia))
266
271
  .WithAttribute("Include", dependencyName)
@@ -274,19 +279,19 @@ internal static class PackageReferenceUpdater
274
279
  if (versionAttribute is null)
275
280
  {
276
281
  // need to add the version
277
- logger.Log(" Adding version attribute to element.");
282
+ logger.Info(" Adding version attribute to element.");
278
283
  updatedPackageVersionElement = existingPackageVersionElement.WithAttribute("Version", newDependencyVersion);
279
284
  }
280
285
  else if (!versionAttribute.Value.Equals(newDependencyVersion, StringComparison.OrdinalIgnoreCase))
281
286
  {
282
287
  // need to update the version
283
- logger.Log($" Updating version attribute of [{versionAttribute.Value}].");
288
+ logger.Info($" Updating version attribute of [{versionAttribute.Value}].");
284
289
  var updatedVersionAttribute = versionAttribute.WithValue(newDependencyVersion);
285
290
  updatedPackageVersionElement = existingPackageVersionElement.ReplaceAttribute(versionAttribute, updatedVersionAttribute);
286
291
  }
287
292
  else
288
293
  {
289
- logger.Log(" Existing PackageVersion element version was already correct.");
294
+ logger.Info(" Existing PackageVersion element version was already correct.");
290
295
  return;
291
296
  }
292
297
 
@@ -302,14 +307,14 @@ internal static class PackageReferenceUpdater
302
307
  var projectDirectory = Path.GetDirectoryName(projectPath)!;
303
308
  await MSBuildHelper.SidelineGlobalJsonAsync(projectDirectory, repoRootPath, async () =>
304
309
  {
305
- logger.Log($" Adding [{dependencyName}/{newDependencyVersion}] as a top-level package reference.");
310
+ logger.Info($" Adding [{dependencyName}/{newDependencyVersion}] as a top-level package reference.");
306
311
 
307
312
  // see https://learn.microsoft.com/nuget/consume-packages/install-use-packages-dotnet-cli
308
313
  var (exitCode, stdout, stderr) = await ProcessEx.RunAsync("dotnet", ["add", projectPath, "package", dependencyName, "--version", newDependencyVersion], workingDirectory: projectDirectory);
309
314
  MSBuildHelper.ThrowOnUnauthenticatedFeed(stdout);
310
315
  if (exitCode != 0)
311
316
  {
312
- logger.Log($" Transitive dependency [{dependencyName}/{newDependencyVersion}] was not added.\nSTDOUT:\n{stdout}\nSTDERR:\n{stderr}");
317
+ logger.Warn($" Transitive dependency [{dependencyName}/{newDependencyVersion}] was not added.\nSTDOUT:\n{stdout}\nSTDERR:\n{stderr}");
313
318
  }
314
319
 
315
320
  return exitCode;
@@ -339,7 +344,7 @@ internal static class PackageReferenceUpdater
339
344
  var unupgradableTfms = tfmsAndDependencies.Where(kvp => !kvp.Value.Any()).Select(kvp => kvp.Key);
340
345
  if (unupgradableTfms.Any())
341
346
  {
342
- logger.Log($" The following target frameworks could not find packages to upgrade: {string.Join(", ", unupgradableTfms)}");
347
+ logger.Info($" The following target frameworks could not find packages to upgrade: {string.Join(", ", unupgradableTfms)}");
343
348
  return null;
344
349
  }
345
350
 
@@ -354,7 +359,7 @@ internal static class PackageReferenceUpdater
354
359
  if (packagesAndVersions.TryGetValue(packageName, out var existingVersion) &&
355
360
  existingVersion != packageVersion)
356
361
  {
357
- logger.Log($" Package [{packageName}] tried to update to version [{packageVersion}], but found conflicting package version of [{existingVersion}].");
362
+ logger.Info($" Package [{packageName}] tried to update to version [{packageVersion}], but found conflicting package version of [{existingVersion}].");
358
363
  conflictingPackageVersionsFound = true;
359
364
  }
360
365
  else
@@ -387,7 +392,7 @@ internal static class PackageReferenceUpdater
387
392
  var result = TryUpdateDependencyVersion(buildFiles, dependencyName, previousDependencyVersion, newDependencyVersion, logger);
388
393
  if (result == UpdateResult.NotFound)
389
394
  {
390
- logger.Log($" Root package [{dependencyName}/{previousDependencyVersion}] was not updated; skipping dependencies.");
395
+ logger.Info($" Root package [{dependencyName}/{previousDependencyVersion}] was not updated; skipping dependencies.");
391
396
  return;
392
397
  }
393
398
 
@@ -405,7 +410,7 @@ internal static class PackageReferenceUpdater
405
410
  var resolvedDependencies = await MSBuildHelper.ResolveDependencyConflictsWithBruteForce(repoRootPath, projectFile.Path, tfm, updatedTopLevelDependencies, logger);
406
411
  if (resolvedDependencies is null)
407
412
  {
408
- logger.Log($" Unable to resolve dependency conflicts for {projectFile.Path}.");
413
+ logger.Info($" Unable to resolve dependency conflicts for {projectFile.Path}.");
409
414
  continue;
410
415
  }
411
416
 
@@ -413,13 +418,13 @@ internal static class PackageReferenceUpdater
413
418
  var specificResolvedDependency = resolvedDependencies.Where(d => d.Name.Equals(dependencyName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
414
419
  if (specificResolvedDependency is null)
415
420
  {
416
- logger.Log($" Unable to resolve requested dependency for {dependencyName} in {projectFile.Path}.");
421
+ logger.Info($" Unable to resolve requested dependency for {dependencyName} in {projectFile.Path}.");
417
422
  continue;
418
423
  }
419
424
 
420
425
  if (!newDependencyVersion.Equals(specificResolvedDependency.Version, StringComparison.OrdinalIgnoreCase))
421
426
  {
422
- logger.Log($" Inconsistent resolution for {dependencyName}; attempted upgrade to {newDependencyVersion} but resolved {specificResolvedDependency.Version}.");
427
+ logger.Info($" Inconsistent resolution for {dependencyName}; attempted upgrade to {newDependencyVersion} but resolved {specificResolvedDependency.Version}.");
423
428
  continue;
424
429
  }
425
430
 
@@ -476,12 +481,12 @@ internal static class PackageReferenceUpdater
476
481
  var currentVersion = versionAttribute.Value.TrimStart('[', '(').TrimEnd(']', ')');
477
482
  if (currentVersion.Contains(',') || currentVersion.Contains('*'))
478
483
  {
479
- logger.Log($" Found unsupported [{packageNode.Name}] version attribute value [{versionAttribute.Value}] in [{buildFile.RelativePath}].");
484
+ logger.Warn($" Found unsupported [{packageNode.Name}] version attribute value [{versionAttribute.Value}] in [{buildFile.RelativePath}].");
480
485
  foundUnsupported = true;
481
486
  }
482
487
  else if (string.Equals(currentVersion, previousDependencyVersion, StringComparison.Ordinal))
483
488
  {
484
- logger.Log($" Found incorrect [{packageNode.Name}] version attribute in [{buildFile.RelativePath}].");
489
+ logger.Info($" Found incorrect [{packageNode.Name}] version attribute in [{buildFile.RelativePath}].");
485
490
  updateNodes.Add(versionAttribute);
486
491
  }
487
492
  else if (previousDependencyVersion == null && NuGetVersion.TryParse(currentVersion, out var previousVersion))
@@ -491,13 +496,13 @@ internal static class PackageReferenceUpdater
491
496
  {
492
497
  previousPackageVersion = currentVersion;
493
498
 
494
- logger.Log($" Found incorrect peer [{packageNode.Name}] version attribute in [{buildFile.RelativePath}].");
499
+ logger.Info($" Found incorrect peer [{packageNode.Name}] version attribute in [{buildFile.RelativePath}].");
495
500
  updateNodes.Add(versionAttribute);
496
501
  }
497
502
  }
498
503
  else if (string.Equals(currentVersion, newDependencyVersion, StringComparison.Ordinal))
499
504
  {
500
- logger.Log($" Found correct [{packageNode.Name}] version attribute in [{buildFile.RelativePath}].");
505
+ logger.Info($" Found correct [{packageNode.Name}] version attribute in [{buildFile.RelativePath}].");
501
506
  foundCorrect = true;
502
507
  }
503
508
  }
@@ -514,12 +519,12 @@ internal static class PackageReferenceUpdater
514
519
  var currentVersion = versionValue.TrimStart('[', '(').TrimEnd(']', ')');
515
520
  if (currentVersion.Contains(',') || currentVersion.Contains('*'))
516
521
  {
517
- logger.Log($" Found unsupported [{packageNode.Name}] version node value [{versionValue}] in [{buildFile.RelativePath}].");
522
+ logger.Info($" Found unsupported [{packageNode.Name}] version node value [{versionValue}] in [{buildFile.RelativePath}].");
518
523
  foundUnsupported = true;
519
524
  }
520
525
  else if (currentVersion == previousDependencyVersion)
521
526
  {
522
- logger.Log($" Found incorrect [{packageNode.Name}] version node in [{buildFile.RelativePath}].");
527
+ logger.Info($" Found incorrect [{packageNode.Name}] version node in [{buildFile.RelativePath}].");
523
528
  if (versionElement is XmlElementSyntax elementSyntax)
524
529
  {
525
530
  updateNodes.Add(elementSyntax);
@@ -536,7 +541,7 @@ internal static class PackageReferenceUpdater
536
541
  {
537
542
  previousPackageVersion = currentVersion;
538
543
 
539
- logger.Log($" Found incorrect peer [{packageNode.Name}] version node in [{buildFile.RelativePath}].");
544
+ logger.Info($" Found incorrect peer [{packageNode.Name}] version node in [{buildFile.RelativePath}].");
540
545
  if (versionElement is XmlElementSyntax elementSyntax)
541
546
  {
542
547
  updateNodes.Add(elementSyntax);
@@ -550,7 +555,7 @@ internal static class PackageReferenceUpdater
550
555
  }
551
556
  else if (currentVersion == newDependencyVersion)
552
557
  {
553
- logger.Log($" Found correct [{packageNode.Name}] version node in [{buildFile.RelativePath}].");
558
+ logger.Info($" Found correct [{packageNode.Name}] version node in [{buildFile.RelativePath}].");
554
559
  foundCorrect = true;
555
560
  }
556
561
  }
@@ -558,7 +563,7 @@ internal static class PackageReferenceUpdater
558
563
  else
559
564
  {
560
565
  // We weren't able to find the version node. Central package management?
561
- logger.Log(" Found package reference but was unable to locate version information.");
566
+ logger.Warn(" Found package reference but was unable to locate version information.");
562
567
  }
563
568
  }
564
569
 
@@ -626,12 +631,12 @@ internal static class PackageReferenceUpdater
626
631
  var currentVersion = propertyContents.TrimStart('[', '(').TrimEnd(']', ')');
627
632
  if (currentVersion.Contains(',') || currentVersion.Contains('*'))
628
633
  {
629
- logger.Log($" Found unsupported version property [{propertyElement.Name}] value [{propertyContents}] in [{buildFile.RelativePath}].");
634
+ logger.Warn($" Found unsupported version property [{propertyElement.Name}] value [{propertyContents}] in [{buildFile.RelativePath}].");
630
635
  foundUnsupported = true;
631
636
  }
632
637
  else if (currentVersion == previousDependencyVersion)
633
638
  {
634
- logger.Log($" Found incorrect version property [{propertyElement.Name}] in [{buildFile.RelativePath}].");
639
+ logger.Info($" Found incorrect version property [{propertyElement.Name}] in [{buildFile.RelativePath}].");
635
640
  updateProperties.Add((XmlElementSyntax)propertyElement.AsNode);
636
641
  }
637
642
  else if (previousDependencyVersion is null && NuGetVersion.TryParse(currentVersion, out var previousVersion))
@@ -641,13 +646,13 @@ internal static class PackageReferenceUpdater
641
646
  {
642
647
  previousPackageVersion = currentVersion;
643
648
 
644
- logger.Log($" Found incorrect peer version property [{propertyElement.Name}] in [{buildFile.RelativePath}].");
649
+ logger.Info($" Found incorrect peer version property [{propertyElement.Name}] in [{buildFile.RelativePath}].");
645
650
  updateProperties.Add((XmlElementSyntax)propertyElement.AsNode);
646
651
  }
647
652
  }
648
653
  else if (currentVersion == newDependencyVersion)
649
654
  {
650
- logger.Log($" Found correct version property [{propertyElement.Name}] in [{buildFile.RelativePath}].");
655
+ logger.Info($" Found correct version property [{propertyElement.Name}] in [{buildFile.RelativePath}].");
651
656
  foundCorrect = true;
652
657
  }
653
658
  }
@@ -701,7 +706,7 @@ internal static class PackageReferenceUpdater
701
706
  var dependenciesAreCoherent = await MSBuildHelper.DependenciesAreCoherentAsync(repoRootPath, projectPath, tfm, updatedPackages, logger);
702
707
  if (!dependenciesAreCoherent)
703
708
  {
704
- logger.Log($" Package [{dependencyName}] could not be updated in [{projectPath}] because it would cause a dependency conflict.");
709
+ logger.Warn($" Package [{dependencyName}] could not be updated in [{projectPath}] because it would cause a dependency conflict.");
705
710
  return false;
706
711
  }
707
712
  }
@@ -715,7 +720,7 @@ internal static class PackageReferenceUpdater
715
720
  {
716
721
  if (await buildFile.SaveAsync())
717
722
  {
718
- logger.Log($" Saved [{buildFile.RelativePath}].");
723
+ logger.Info($" Saved [{buildFile.RelativePath}].");
719
724
  }
720
725
  }
721
726
  }
@@ -9,6 +9,7 @@ using Microsoft.Language.Xml;
9
9
  using NuGet.CommandLine;
10
10
 
11
11
  using NuGetUpdater.Core.Updater;
12
+ using NuGetUpdater.Core.Utilities;
12
13
 
13
14
  using Console = System.Console;
14
15
 
@@ -35,18 +36,18 @@ internal static class PackagesConfigUpdater
35
36
  )
36
37
  {
37
38
  // packages.config project; use NuGet.exe to perform update
38
- logger.Log($" Found '{NuGetHelper.PackagesConfigFileName}' project; running NuGet.exe update");
39
+ logger.Info($" Found '{ProjectHelper.PackagesConfigFileName}' project; running NuGet.exe update");
39
40
 
40
41
  // ensure local packages directory exists
41
42
  var projectBuildFile = ProjectBuildFile.Open(repoRootPath, projectPath);
42
43
  var packagesSubDirectory = GetPathToPackagesDirectory(projectBuildFile, dependencyName, previousDependencyVersion, packagesConfigPath);
43
44
  if (packagesSubDirectory is null)
44
45
  {
45
- logger.Log($" Project [{projectPath}] does not reference this dependency.");
46
+ logger.Info($" Project [{projectPath}] does not reference this dependency.");
46
47
  return;
47
48
  }
48
49
 
49
- logger.Log($" Using packages directory [{packagesSubDirectory}] for project [{projectPath}].");
50
+ logger.Info($" Using packages directory [{packagesSubDirectory}] for project [{projectPath}].");
50
51
 
51
52
  var projectDirectory = Path.GetDirectoryName(projectPath);
52
53
  var packagesDirectory = PathHelper.JoinPath(projectDirectory, packagesSubDirectory);
@@ -74,7 +75,7 @@ internal static class PackagesConfigUpdater
74
75
  "-NonInteractive",
75
76
  };
76
77
 
77
- logger.Log(" Finding MSBuild...");
78
+ logger.Info(" Finding MSBuild...");
78
79
  var msbuildDirectory = MSBuildHelper.MSBuildPath;
79
80
  if (msbuildDirectory is not null)
80
81
  {
@@ -96,7 +97,7 @@ internal static class PackagesConfigUpdater
96
97
  // Update binding redirects
97
98
  await BindingRedirectManager.UpdateBindingRedirectsAsync(projectBuildFile, dependencyName, newDependencyVersion);
98
99
 
99
- logger.Log(" Writing project file back to disk");
100
+ logger.Info(" Writing project file back to disk");
100
101
  await projectBuildFile.SaveAsync();
101
102
  }
102
103
 
@@ -118,12 +119,12 @@ internal static class PackagesConfigUpdater
118
119
  var retryingAfterRestore = false;
119
120
 
120
121
  doRestore:
121
- logger.Log($" Running NuGet.exe with args: {string.Join(" ", updateArgs)}");
122
+ logger.Info($" Running NuGet.exe with args: {string.Join(" ", updateArgs)}");
122
123
  outputBuilder.Clear();
123
124
  var result = Program.Main(updateArgs.ToArray());
124
125
  var fullOutput = outputBuilder.ToString();
125
- logger.Log($" Result: {result}");
126
- logger.Log($" Output:\n{fullOutput}");
126
+ logger.Info($" Result: {result}");
127
+ logger.Info($" Output:\n{fullOutput}");
127
128
  if (result != 0)
128
129
  {
129
130
  // The initial `update` command can fail for several reasons:
@@ -140,7 +141,7 @@ internal static class PackagesConfigUpdater
140
141
  if (!retryingAfterRestore && OutputIndicatesRestoreIsRequired(fullOutput))
141
142
  {
142
143
  retryingAfterRestore = true;
143
- logger.Log($" Running NuGet.exe with args: {string.Join(" ", restoreArgs)}");
144
+ logger.Info($" Running NuGet.exe with args: {string.Join(" ", restoreArgs)}");
144
145
  outputBuilder.Clear();
145
146
  var exitCodeAgain = Program.Main(restoreArgs.ToArray());
146
147
  var restoreOutput = outputBuilder.ToString();
@@ -164,7 +165,7 @@ internal static class PackagesConfigUpdater
164
165
  }
165
166
  catch (Exception e)
166
167
  {
167
- logger.Log($"Error: {e}");
168
+ logger.Info($"Error: {e}");
168
169
  throw;
169
170
  }
170
171
  finally
@@ -178,7 +179,7 @@ internal static class PackagesConfigUpdater
178
179
  var deltaSpawnedProcesses = currentSpawnedProcesses.Except(existingSpawnedProcesses).ToArray();
179
180
  foreach (var credProvider in deltaSpawnedProcesses)
180
181
  {
181
- logger.Log($"Ending spawned credential provider process");
182
+ logger.Info($"Ending spawned credential provider process");
182
183
  credProvider.Kill();
183
184
  }
184
185
  }
@@ -4,6 +4,7 @@ using System.Text.Json.Serialization;
4
4
 
5
5
  using NuGetUpdater.Core.Analyze;
6
6
  using NuGetUpdater.Core.Updater;
7
+ using NuGetUpdater.Core.Utilities;
7
8
 
8
9
  namespace NuGetUpdater.Core;
9
10
 
@@ -114,11 +115,11 @@ public class UpdaterWorker : IUpdaterWorker
114
115
  await RunForProjectAsync(repoRootPath, workspacePath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive);
115
116
  break;
116
117
  default:
117
- _logger.Log($"File extension [{extension}] is not supported.");
118
+ _logger.Info($"File extension [{extension}] is not supported.");
118
119
  break;
119
120
  }
120
121
 
121
- _logger.Log("Update complete.");
122
+ _logger.Info("Update complete.");
122
123
 
123
124
  _processedProjectPaths.Clear();
124
125
  return new UpdateOperationResult();
@@ -126,7 +127,7 @@ public class UpdaterWorker : IUpdaterWorker
126
127
 
127
128
  internal static async Task WriteResultFile(UpdateOperationResult result, string resultOutputPath, ILogger logger)
128
129
  {
129
- logger.Log($" Writing update result to [{resultOutputPath}].");
130
+ logger.Info($" Writing update result to [{resultOutputPath}].");
130
131
 
131
132
  var resultJson = JsonSerializer.Serialize(result, SerializerOptions);
132
133
  await File.WriteAllTextAsync(resultOutputPath, resultJson);
@@ -140,7 +141,7 @@ public class UpdaterWorker : IUpdaterWorker
140
141
  string newDependencyVersion,
141
142
  bool isTransitive)
142
143
  {
143
- _logger.Log($"Running for solution [{Path.GetRelativePath(repoRootPath, solutionPath)}]");
144
+ _logger.Info($"Running for solution [{Path.GetRelativePath(repoRootPath, solutionPath)}]");
144
145
  var projectPaths = MSBuildHelper.GetProjectPathsFromSolution(solutionPath);
145
146
  foreach (var projectPath in projectPaths)
146
147
  {
@@ -156,10 +157,10 @@ public class UpdaterWorker : IUpdaterWorker
156
157
  string newDependencyVersion,
157
158
  bool isTransitive)
158
159
  {
159
- _logger.Log($"Running for proj file [{Path.GetRelativePath(repoRootPath, projFilePath)}]");
160
+ _logger.Info($"Running for proj file [{Path.GetRelativePath(repoRootPath, projFilePath)}]");
160
161
  if (!File.Exists(projFilePath))
161
162
  {
162
- _logger.Log($"File [{projFilePath}] does not exist.");
163
+ _logger.Info($"File [{projFilePath}] does not exist.");
163
164
  return;
164
165
  }
165
166
 
@@ -182,10 +183,10 @@ public class UpdaterWorker : IUpdaterWorker
182
183
  string newDependencyVersion,
183
184
  bool isTransitive)
184
185
  {
185
- _logger.Log($"Running for project file [{Path.GetRelativePath(repoRootPath, projectPath)}]");
186
+ _logger.Info($"Running for project file [{Path.GetRelativePath(repoRootPath, projectPath)}]");
186
187
  if (!File.Exists(projectPath))
187
188
  {
188
- _logger.Log($"File [{projectPath}] does not exist.");
189
+ _logger.Info($"File [{projectPath}] does not exist.");
189
190
  return;
190
191
  }
191
192
 
@@ -215,18 +216,21 @@ public class UpdaterWorker : IUpdaterWorker
215
216
 
216
217
  _processedProjectPaths.Add(projectPath);
217
218
 
218
- _logger.Log($"Updating project [{projectPath}]");
219
+ _logger.Info($"Updating project [{projectPath}]");
219
220
 
220
- if (NuGetHelper.TryGetPackagesConfigFile(projectPath, out var packagesConfigPath))
221
+ var additionalFiles = ProjectHelper.GetAllAdditionalFilesFromProject(projectPath, ProjectHelper.PathFormat.Full);
222
+ var packagesConfigFullPath = additionalFiles.Where(p => Path.GetFileName(p).Equals(ProjectHelper.PackagesConfigFileName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
223
+ if (packagesConfigFullPath is not null)
221
224
  {
222
- await PackagesConfigUpdater.UpdateDependencyAsync(repoRootPath, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, packagesConfigPath, _logger);
225
+ await PackagesConfigUpdater.UpdateDependencyAsync(repoRootPath, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, packagesConfigFullPath, _logger);
223
226
  }
224
227
 
225
228
  // Some repos use a mix of packages.config and PackageReference
226
229
  await PackageReferenceUpdater.UpdateDependencyAsync(repoRootPath, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive, _experimentsManager, _logger);
227
230
 
228
231
  // Update lock file if exists
229
- if (File.Exists(Path.Combine(Path.GetDirectoryName(projectPath), "packages.lock.json")))
232
+ var packagesLockFullPath = additionalFiles.Where(p => Path.GetFileName(p).Equals(ProjectHelper.PackagesLockJsonFileName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
233
+ if (packagesLockFullPath is not null)
230
234
  {
231
235
  await LockFileUpdater.UpdateLockFileAsync(repoRootPath, projectPath, _logger);
232
236
  }
@@ -2,7 +2,7 @@ namespace NuGetUpdater.Core;
2
2
 
3
3
  public sealed class ConsoleLogger : ILogger
4
4
  {
5
- public void Log(string message)
5
+ public void LogRaw(string message)
6
6
  {
7
7
  Console.WriteLine(message);
8
8
  }
@@ -136,7 +136,7 @@ public class PackageManager
136
136
  }
137
137
 
138
138
  // Method to get the dependencies of a package
139
- public async Task<List<PackageToUpdate>> GetDependenciesAsync(PackageToUpdate package, string targetFramework, string projectDirectory)
139
+ public async Task<List<PackageToUpdate>> GetDependenciesAsync(PackageToUpdate package, string targetFramework, string projectDirectory, ILogger logger)
140
140
  {
141
141
  if (!NuGetVersion.TryParse(package.NewVersion, out var otherVersion))
142
142
  {
@@ -235,24 +235,24 @@ public class PackageManager
235
235
  }
236
236
  else
237
237
  {
238
- Console.WriteLine("No compatible framework found.");
238
+ logger.Info("No compatible framework found.");
239
239
  }
240
240
  }
241
241
  catch (HttpRequestException ex)
242
242
  {
243
- Console.WriteLine($"HTTP error occurred: {ex.Message}");
243
+ logger.Error($"HTTP error occurred: {ex.Message}");
244
244
  }
245
245
  catch (ArgumentNullException ex)
246
246
  {
247
- Console.WriteLine($"Argument is null error: {ex.ParamName}, {ex.Message}");
247
+ logger.Error($"Argument is null error: {ex.ParamName}, {ex.Message}");
248
248
  }
249
249
  catch (InvalidOperationException ex)
250
250
  {
251
- Console.WriteLine($"Invalid operation exception: {ex.Message}");
251
+ logger.Error($"Invalid operation exception: {ex.Message}");
252
252
  }
253
253
  catch (Exception ex)
254
254
  {
255
- Console.WriteLine($"An error occurred: {ex.Message}");
255
+ logger.Error($"An error occurred: {ex.Message}");
256
256
  }
257
257
 
258
258
  return dependencyList;
@@ -287,12 +287,12 @@ public class PackageManager
287
287
  }
288
288
 
289
289
  // Method to get the dependencies of a package and add them as a dependency
290
- public async Task PopulatePackageDependenciesAsync(List<PackageToUpdate> packages, string targetFramework, string projectDirectory)
290
+ public async Task PopulatePackageDependenciesAsync(List<PackageToUpdate> packages, string targetFramework, string projectDirectory, ILogger logger)
291
291
  {
292
292
  // Loop through each package and get their dependencies
293
293
  foreach (PackageToUpdate package in packages)
294
294
  {
295
- List<PackageToUpdate> dependencies = await GetDependenciesAsync(package, targetFramework, projectDirectory);
295
+ List<PackageToUpdate> dependencies = await GetDependenciesAsync(package, targetFramework, projectDirectory, logger);
296
296
 
297
297
  if (dependencies == null)
298
298
  {
@@ -366,7 +366,7 @@ public class PackageManager
366
366
  package.CurrentVersion = package.NewVersion;
367
367
 
368
368
  // Check if the current package has dependencies
369
- List<PackageToUpdate> dependencyList = await GetDependenciesAsync(package, targetFramework, projectDirectory);
369
+ List<PackageToUpdate> dependencyList = await GetDependenciesAsync(package, targetFramework, projectDirectory, logger);
370
370
 
371
371
  // If there are dependencies
372
372
  if (dependencyList != null)
@@ -426,7 +426,7 @@ public class PackageManager
426
426
 
427
427
  foreach (PackageToUpdate parent in parentPackages)
428
428
  {
429
- bool isCompatible = await IsCompatibleAsync(parent, package, targetFramework, projectDirectory);
429
+ bool isCompatible = await IsCompatibleAsync(parent, package, targetFramework, projectDirectory, logger);
430
430
 
431
431
  // If the parent and package are not compatible
432
432
  if (!isCompatible)
@@ -446,7 +446,7 @@ public class PackageManager
446
446
  // If it's compatible and the package you updated wasn't in the existing package, check if the parent's dependencies version is the same as the current version
447
447
  else if (isCompatible == true && inExisting == false)
448
448
  {
449
- List<PackageToUpdate> dependencyListParent = await GetDependenciesAsync(parent, targetFramework, projectDirectory);
449
+ List<PackageToUpdate> dependencyListParent = await GetDependenciesAsync(parent, targetFramework, projectDirectory, logger);
450
450
 
451
451
  PackageToUpdate parentDependency = dependencyListParent.FirstOrDefault(p => string.Compare(p.PackageName, package.PackageName, StringComparison.OrdinalIgnoreCase) == 0);
452
452
 
@@ -478,7 +478,7 @@ public class PackageManager
478
478
  parent.NewVersion = parentVersion;
479
479
 
480
480
  // Check if the parent needs to be updated since the child isn't in the existing package list and the parent can update to a newer version to remove the dependency
481
- List<PackageToUpdate> dependencyListParentTemp = await GetDependenciesAsync(parent, targetFramework, projectDirectory);
481
+ List<PackageToUpdate> dependencyListParentTemp = await GetDependenciesAsync(parent, targetFramework, projectDirectory, logger);
482
482
  PackageToUpdate parentDependencyTemp = dependencyListParentTemp.FirstOrDefault(p => string.Compare(p.PackageName, package.PackageName, StringComparison.OrdinalIgnoreCase) == 0);
483
483
 
484
484
  // If the newer package version of the parent has the same version as the parent's previous dependency, update
@@ -499,7 +499,7 @@ public class PackageManager
499
499
 
500
500
  else
501
501
  {
502
- Console.WriteLine("Current version is >= latest version");
502
+ logger.Info("Current version is >= latest version");
503
503
  }
504
504
  }
505
505
  catch
@@ -511,10 +511,10 @@ public class PackageManager
511
511
  }
512
512
 
513
513
  // Method to determine if a parent and child are compatible with their versions
514
- public async Task<bool> IsCompatibleAsync(PackageToUpdate parent, PackageToUpdate child, string targetFramework, string projectDirectory)
514
+ public async Task<bool> IsCompatibleAsync(PackageToUpdate parent, PackageToUpdate child, string targetFramework, string projectDirectory, ILogger logger)
515
515
  {
516
516
  // Get the dependencies of the parent
517
- List<PackageToUpdate> dependencies = await GetDependenciesAsync(parent, targetFramework, projectDirectory);
517
+ List<PackageToUpdate> dependencies = await GetDependenciesAsync(parent, targetFramework, projectDirectory, logger);
518
518
 
519
519
  foreach (PackageToUpdate dependency in dependencies)
520
520
  {
@@ -613,7 +613,7 @@ public class PackageManager
613
613
  }
614
614
 
615
615
  // Check if there's compatibility with parent and dependency
616
- if (await IsCompatibleAsync(possibleParent, possibleDependency, targetFramework, nugetContext.CurrentDirectory))
616
+ if (await IsCompatibleAsync(possibleParent, possibleDependency, targetFramework, nugetContext.CurrentDirectory, logger))
617
617
  {
618
618
  // Check if parents are compatible, recursively
619
619
  if (await AreAllParentsCompatibleAsync(existingPackages, possibleParent, targetFramework, nugetContext.CurrentDirectory, logger))
@@ -641,7 +641,7 @@ public class PackageManager
641
641
  foreach (PackageToUpdate parent in parentPackages)
642
642
  {
643
643
  // Check compatibility between the possibleParent and current parent
644
- bool isCompatible = await IsCompatibleAsync(parent, possibleParent, targetFramework, projectDirectory);
644
+ bool isCompatible = await IsCompatibleAsync(parent, possibleParent, targetFramework, projectDirectory, logger);
645
645
 
646
646
  // If the possibleParent and parent are not compatible
647
647
  if (!isCompatible)
@@ -668,7 +668,7 @@ public class PackageManager
668
668
  }
669
669
 
670
670
  // Method to update the existing packages with new version of the desired packages to update
671
- public void UpdateExistingPackagesWithNewVersions(List<PackageToUpdate> existingPackages, List<PackageToUpdate> packagesToUpdate)
671
+ public void UpdateExistingPackagesWithNewVersions(List<PackageToUpdate> existingPackages, List<PackageToUpdate> packagesToUpdate, ILogger logger)
672
672
  {
673
673
  foreach (PackageToUpdate packageToUpdate in packagesToUpdate)
674
674
  {
@@ -680,7 +680,7 @@ public class PackageManager
680
680
  }
681
681
  else
682
682
  {
683
- Console.WriteLine($"Package {packageToUpdate.PackageName} not found in existing packages");
683
+ logger.Info($"Package {packageToUpdate.PackageName} not found in existing packages");
684
684
  }
685
685
  }
686
686
  }
@@ -2,5 +2,15 @@ namespace NuGetUpdater.Core;
2
2
 
3
3
  public interface ILogger
4
4
  {
5
- void Log(string message);
5
+ void LogRaw(string message);
6
+ }
7
+
8
+ public static class LoggerExtensions
9
+ {
10
+ public static void Info(this ILogger logger, string message) => logger.LogWithLevel("INFO", message);
11
+ public static void Warn(this ILogger logger, string message) => logger.LogWithLevel("WARN", message);
12
+ public static void Error(this ILogger logger, string message) => logger.LogWithLevel("ERROR", message);
13
+
14
+ private static void LogWithLevel(this ILogger logger, string level, string message) => logger.LogRaw($"{GetCurrentTimestamp()} {level} {message}");
15
+ private static string GetCurrentTimestamp() => DateTime.UtcNow.ToString("yyyy/MM/dd HH:mm:ss");
6
16
  }