dependabot-nuget 0.284.0 → 0.286.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Build.props +5 -1
  3. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/NuGet.CommandLine.csproj +1 -0
  4. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Configuration/NuGet.Configuration.csproj +1 -0
  5. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.LibraryModel/NuGet.LibraryModel.csproj +1 -0
  6. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Packaging/NuGet.Packaging.csproj +1 -1
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/RunCommand.cs +8 -1
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +7 -3
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +11 -0
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Analyze/AnalyzeWorker.cs +1 -1
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs +2 -2
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +52 -0
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/IAnalyzeWorker.cs +9 -0
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/IDiscoveryWorker.cs +8 -0
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/IUpdaterWorker.cs +9 -0
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +104 -33
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +6 -5
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +37 -5
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +5 -3
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +0 -5
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +2 -0
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +975 -57
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +168 -0
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatedDependencyListTests.cs +53 -6
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestAnalyzeWorker.cs +37 -0
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestDiscoveryWorker.cs +35 -0
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestUpdaterWorker.cs +39 -0
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +104 -3
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +51 -13
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DirsProj.cs +4 -2
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs +22 -17
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +1 -1
  33. data/lib/dependabot/nuget/file_updater.rb +8 -3
  34. data/lib/dependabot/nuget/native_helpers.rb +11 -12
  35. metadata +12 -6
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/DependencySolverEnvironment.cs +0 -12
@@ -1,5 +1,6 @@
1
1
  using System.Diagnostics;
2
2
  using System.Text;
3
+ using System.Text.RegularExpressions;
3
4
  using System.Xml.Linq;
4
5
  using System.Xml.XPath;
5
6
 
@@ -213,8 +214,8 @@ internal static class PackagesConfigUpdater
213
214
  var hintPathSubString = $"{dependencyName}.{dependencyVersion}";
214
215
 
215
216
  string? partialPathMatch = null;
216
- var hintPathNodes = projectBuildFile.Contents.Descendants().Where(e => e.IsHintPathNodeForDependency(dependencyName));
217
- foreach (var hintPathNode in hintPathNodes)
217
+ var specificHintPathNodes = projectBuildFile.Contents.Descendants().Where(e => e.IsHintPathNodeForDependency(dependencyName)).ToArray();
218
+ foreach (var hintPathNode in specificHintPathNodes)
218
219
  {
219
220
  var hintPath = hintPathNode.GetContentValue();
220
221
  var hintPathSubStringLocation = hintPath.IndexOf(hintPathSubString, StringComparison.OrdinalIgnoreCase);
@@ -255,18 +256,49 @@ internal static class PackagesConfigUpdater
255
256
  if (hasPackage)
256
257
  {
257
258
  // the dependency exists in the packages.config file, so it must be the second case
258
- // the vast majority of projects found in the wild use this, and since we have nothing to look for, we'll just have to hope
259
- partialPathMatch = "../packages";
259
+ // at this point there's no perfect way to determine what the packages path is, but there's a really good chance that
260
+ // for any given package it looks something like this:
261
+ // ..\..\packages\Package.Name.[version]\lib\Tfm\Package.Name.dll
262
+ var genericHintPathNodes = projectBuildFile.Contents.Descendants().Where(IsHintPathNode).ToArray();
263
+ if (genericHintPathNodes.Length > 0)
264
+ {
265
+ foreach (var hintPathNode in genericHintPathNodes)
266
+ {
267
+ 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
270
+ if (match.Success)
271
+ {
272
+ partialPathMatch = match.Groups["PackagesPath"].Value;
273
+ break;
274
+ }
275
+ }
276
+ }
277
+ else
278
+ {
279
+ // we know the dependency is used, but we have absolutely no idea where the packages path is, so we'll default to something reasonable
280
+ partialPathMatch = "../packages";
281
+ }
260
282
  }
261
283
  }
262
284
 
263
285
  return partialPathMatch?.NormalizePathToUnix();
264
286
  }
265
287
 
266
- private static bool IsHintPathNodeForDependency(this IXmlElementSyntax element, string dependencyName)
288
+ private static bool IsHintPathNode(this IXmlElementSyntax element)
267
289
  {
268
290
  if (element.Name.Equals("HintPath", StringComparison.OrdinalIgnoreCase) &&
269
291
  element.Parent.Name.Equals("Reference", StringComparison.OrdinalIgnoreCase))
292
+ {
293
+ return true;
294
+ }
295
+
296
+ return false;
297
+ }
298
+
299
+ private static bool IsHintPathNodeForDependency(this IXmlElementSyntax element, string dependencyName)
300
+ {
301
+ if (element.IsHintPathNode())
270
302
  {
271
303
  // the include attribute will look like one of the following:
272
304
  // <Reference Include="Some.Dependency, Version=1.0.0.0, Culture=neutral, PublicKeyToken=abcd">
@@ -7,8 +7,9 @@ using NuGetUpdater.Core.Updater;
7
7
 
8
8
  namespace NuGetUpdater.Core;
9
9
 
10
- public class UpdaterWorker
10
+ public class UpdaterWorker : IUpdaterWorker
11
11
  {
12
+ private readonly ExperimentsManager _experimentsManager;
12
13
  private readonly ILogger _logger;
13
14
  private readonly HashSet<string> _processedProjectPaths = new(StringComparer.OrdinalIgnoreCase);
14
15
 
@@ -18,8 +19,9 @@ public class UpdaterWorker
18
19
  Converters = { new JsonStringEnumConverter() },
19
20
  };
20
21
 
21
- public UpdaterWorker(ILogger logger)
22
+ public UpdaterWorker(ExperimentsManager experimentsManager, ILogger logger)
22
23
  {
24
+ _experimentsManager = experimentsManager;
23
25
  _logger = logger;
24
26
  }
25
27
 
@@ -221,7 +223,7 @@ public class UpdaterWorker
221
223
  }
222
224
 
223
225
  // Some repos use a mix of packages.config and PackageReference
224
- await PackageReferenceUpdater.UpdateDependencyAsync(repoRootPath, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive, _logger);
226
+ await PackageReferenceUpdater.UpdateDependencyAsync(repoRootPath, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive, _experimentsManager, _logger);
225
227
 
226
228
  // Update lock file if exists
227
229
  if (File.Exists(Path.Combine(Path.GetDirectoryName(projectPath), "packages.lock.json")))
@@ -335,11 +335,6 @@ internal static partial class MSBuildHelper
335
335
  }
336
336
  }
337
337
 
338
- internal static bool UseNewDependencySolver()
339
- {
340
- return Environment.GetEnvironmentVariable("UseNewNugetPackageResolver") == "true";
341
- }
342
-
343
338
  internal static async Task<Dependency[]?> ResolveDependencyConflicts(string repoRoot, string projectPath, string targetFramework, Dependency[] packages, Dependency[] update, ILogger logger)
344
339
  {
345
340
  var tempDirectory = Directory.CreateTempSubdirectory("package-dependency-coherence_");
@@ -63,6 +63,8 @@ internal static class PathHelper
63
63
  return result;
64
64
  }
65
65
 
66
+ public static string FullyNormalizedRootedPath(this string path) => path.NormalizePathToUnix().NormalizeUnixPathParts().EnsurePrefix("/");
67
+
66
68
  public static string GetFullPathFromRelative(string rootPath, string relativePath)
67
69
  => Path.GetFullPath(JoinPath(rootPath, relativePath.NormalizePathToUnix()));
68
70