dependabot-nuget 0.288.0 → 0.290.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) 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/Commands/AnalyzeCommand.cs +7 -3
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/RunCommand.cs +1 -1
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Analyze.cs +29 -2
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Discover.cs +25 -4
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Run.cs +0 -6
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/AnalyzeWorker.cs +33 -16
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/CompatabilityChecker.cs +25 -10
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/NuGetContext.cs +0 -13
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/RequirementArrayConverter.cs +39 -0
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/VersionFinder.cs +1 -1
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Clone/ShellGitCommandHandler.cs +1 -1
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs +60 -66
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DotNetToolsJsonDiscovery.cs +2 -2
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/GlobalJsonDiscovery.cs +2 -2
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/PackagesConfigDiscovery.cs +11 -3
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/PackagesConfigDiscoveryResult.cs +1 -0
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs +2 -4
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +54 -11
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/WorkspaceDiscoveryResult.cs +0 -1
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +1 -2
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +1 -1
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/CompatabilityChecker.cs +2 -2
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Advisory.cs +13 -0
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/AllowedUpdate.cs +18 -1
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/CommitOptions.cs +8 -0
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Condition.cs +19 -0
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/DependencyGroup.cs +8 -0
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/GroupPullRequest.cs +9 -0
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/Job.cs +13 -10
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/PullRequest.cs +11 -0
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/RequirementsUpdateStrategy.cs +15 -0
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +67 -58
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/VersionConverter.cs +19 -0
  37. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs +15 -44
  38. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +4 -4
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +5 -5
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/LockFileUpdater.cs +2 -10
  41. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +38 -33
  42. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +25 -23
  43. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +16 -12
  44. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ConsoleLogger.cs +1 -1
  45. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/DependencyConflictResolver.cs +19 -19
  46. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ILogger.cs +11 -1
  47. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/JsonHelper.cs +2 -0
  48. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +18 -17
  49. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/NuGetHelper.cs +1 -17
  50. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +17 -9
  51. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProjectHelper.cs +96 -0
  52. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTestBase.cs +5 -2
  53. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTests.cs +87 -5
  54. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTestBase.cs +2 -5
  55. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.DotNetToolsJson.cs +45 -1
  56. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.GlobalJson.cs +35 -1
  57. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.PackagesConfig.cs +16 -0
  58. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.Proj.cs +6 -0
  59. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.Project.cs +143 -36
  60. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +184 -48
  61. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/ExpectedDiscoveryResults.cs +5 -5
  62. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs +32 -10
  63. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MiscellaneousTests.cs +85 -0
  64. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +402 -102
  65. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +342 -2
  66. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatedDependencyListTests.cs +60 -2
  67. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TemporaryDirectory.cs +18 -7
  68. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestLogger.cs +1 -1
  69. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/BindingRedirectsTests.cs +1 -1
  70. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +24 -0
  71. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +4 -14
  72. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DotNetTools.cs +84 -0
  73. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +66 -0
  74. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs +95 -0
  75. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +1 -7
  76. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/AssertEx.cs +1 -1
  77. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/LinuxOnlyAttribute.cs +12 -0
  78. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +558 -711
  79. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/PathHelperTests.cs +47 -2
  80. data/lib/dependabot/nuget/analysis/analysis_json_reader.rb +4 -2
  81. data/lib/dependabot/nuget/analysis/dependency_analysis.rb +3 -3
  82. data/lib/dependabot/nuget/discovery/dependency_details.rb +10 -3
  83. data/lib/dependabot/nuget/discovery/dependency_file_discovery.rb +8 -12
  84. data/lib/dependabot/nuget/discovery/discovery_json_reader.rb +214 -29
  85. data/lib/dependabot/nuget/discovery/project_discovery.rb +41 -8
  86. data/lib/dependabot/nuget/discovery/workspace_discovery.rb +14 -19
  87. data/lib/dependabot/nuget/file_fetcher.rb +11 -393
  88. data/lib/dependabot/nuget/file_parser.rb +23 -61
  89. data/lib/dependabot/nuget/file_updater.rb +28 -23
  90. data/lib/dependabot/nuget/native_helpers.rb +14 -5
  91. data/lib/dependabot/nuget/update_checker/requirements_updater.rb +23 -27
  92. data/lib/dependabot/nuget/update_checker.rb +116 -190
  93. metadata +20 -32
  94. data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Packages.props +0 -29
  95. data/lib/dependabot/nuget/discovery/directory_packages_props_discovery.rb +0 -43
  96. data/lib/dependabot/nuget/file_fetcher/import_paths_finder.rb +0 -73
  97. data/lib/dependabot/nuget/file_fetcher/sln_project_paths_finder.rb +0 -60
  98. data/lib/dependabot/nuget/http_response_helpers.rb +0 -19
  99. data/lib/dependabot/nuget/native_discovery/native_dependency_details.rb +0 -102
  100. data/lib/dependabot/nuget/native_discovery/native_dependency_file_discovery.rb +0 -129
  101. data/lib/dependabot/nuget/native_discovery/native_discovery_json_reader.rb +0 -171
  102. data/lib/dependabot/nuget/native_discovery/native_evaluation_details.rb +0 -63
  103. data/lib/dependabot/nuget/native_discovery/native_project_discovery.rb +0 -82
  104. data/lib/dependabot/nuget/native_discovery/native_property_details.rb +0 -43
  105. data/lib/dependabot/nuget/native_discovery/native_workspace_discovery.rb +0 -68
  106. data/lib/dependabot/nuget/native_update_checker/native_requirements_updater.rb +0 -105
  107. data/lib/dependabot/nuget/native_update_checker/native_update_checker.rb +0 -201
  108. data/lib/dependabot/nuget/nuget_client.rb +0 -223
  109. data/lib/dependabot/nuget/update_checker/compatibility_checker.rb +0 -116
  110. data/lib/dependabot/nuget/update_checker/dependency_finder.rb +0 -297
  111. data/lib/dependabot/nuget/update_checker/nupkg_fetcher.rb +0 -221
  112. data/lib/dependabot/nuget/update_checker/nuspec_fetcher.rb +0 -110
  113. data/lib/dependabot/nuget/update_checker/property_updater.rb +0 -196
  114. data/lib/dependabot/nuget/update_checker/repository_finder.rb +0 -466
  115. data/lib/dependabot/nuget/update_checker/tfm_comparer.rb +0 -34
  116. data/lib/dependabot/nuget/update_checker/tfm_finder.rb +0 -30
  117. data/lib/dependabot/nuget/update_checker/version_finder.rb +0 -449
@@ -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
 
@@ -22,7 +23,7 @@ namespace NuGetUpdater.Core;
22
23
  /// See: https://learn.microsoft.com/en-us/nuget/reference/packages-config
23
24
  /// https://learn.microsoft.com/en-us/nuget/resources/check-project-format
24
25
  /// <remarks>
25
- internal static class PackagesConfigUpdater
26
+ internal static partial class PackagesConfigUpdater
26
27
  {
27
28
  public static async Task UpdateDependencyAsync(
28
29
  string repoRootPath,
@@ -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
  }
@@ -214,7 +215,7 @@ internal static class PackagesConfigUpdater
214
215
  var hintPathSubString = $"{dependencyName}.{dependencyVersion}";
215
216
 
216
217
  string? partialPathMatch = null;
217
- var specificHintPathNodes = projectBuildFile.Contents.Descendants().Where(e => e.IsHintPathNodeForDependency(dependencyName)).ToArray();
218
+ var specificHintPathNodes = projectBuildFile.Contents.Descendants().Where(e => e.IsHintPathNodeForDependency(dependencyName, dependencyVersion)).ToArray();
218
219
  foreach (var hintPathNode in specificHintPathNodes)
219
220
  {
220
221
  var hintPath = hintPathNode.GetContentValue();
@@ -265,8 +266,7 @@ internal static class PackagesConfigUpdater
265
266
  foreach (var hintPathNode in genericHintPathNodes)
266
267
  {
267
268
  var hintPath = hintPathNode.GetContentValue();
268
- var match = Regex.Match(hintPath, @"^(?<PackagesPath>.*)[/\\](?<PackageNameAndVersion>[^/\\]+)[/\\]lib[/\\](?<Tfm>[^/\\]+)[/\\](?<AssemblyName>[^/\\]+)$");
269
- // e.g., ..\..\packages \ Some.Package.1.2.3 \ lib\ net45 \ Some.Package.dll
269
+ var match = PackageAssemblyHintPathPattern().Match(hintPath);
270
270
  if (match.Success)
271
271
  {
272
272
  partialPathMatch = match.Groups["PackagesPath"].Value;
@@ -296,17 +296,15 @@ internal static class PackagesConfigUpdater
296
296
  return false;
297
297
  }
298
298
 
299
- private static bool IsHintPathNodeForDependency(this IXmlElementSyntax element, string dependencyName)
299
+ private static bool IsHintPathNodeForDependency(this IXmlElementSyntax element, string dependencyName, string dependencyVersion)
300
300
  {
301
301
  if (element.IsHintPathNode())
302
302
  {
303
- // the include attribute will look like one of the following:
304
- // <Reference Include="Some.Dependency, Version=1.0.0.0, Culture=neutral, PublicKeyToken=abcd">
305
- // or
306
- // <Reference Include="Some.Dependency">
307
- string includeAttributeValue = element.Parent.GetAttributeValue("Include", StringComparison.OrdinalIgnoreCase);
308
- if (includeAttributeValue.Equals(dependencyName, StringComparison.OrdinalIgnoreCase) ||
309
- includeAttributeValue.StartsWith($"{dependencyName},", StringComparison.OrdinalIgnoreCase))
303
+ // the hint path will look similar to this:
304
+ // ..\packages\Some.Package.1.2.3\lib\net45\Some.Package.dll
305
+ var assemblyPath = element.GetContentValue();
306
+ var match = PackageAssemblyHintPathPattern().Match(assemblyPath);
307
+ if (match.Success)
310
308
  {
311
309
  return true;
312
310
  }
@@ -325,4 +323,8 @@ internal static class PackagesConfigUpdater
325
323
 
326
324
  return subpath;
327
325
  }
326
+
327
+ [GeneratedRegex(@"^(?<PackagesPath>.*)[/\\](?<PackageNameAndVersion>[^/\\]+)[/\\]lib[/\\](?<Tfm>[^/\\]+)[/\\](?<AssemblyName>[^/\\]+)$", RegexOptions.IgnoreCase)]
328
+ // e.g., ..\..\packages \ Some.Package.1.2.3 \ lib \ net45 \ Some.Package.dll
329
+ private static partial Regex PackageAssemblyHintPathPattern();
328
330
  }
@@ -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
  }