dependabot-nuget 0.242.1 → 0.243.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/.editorconfig +37 -28
  3. data/helpers/lib/NuGetUpdater/.gitignore +1 -0
  4. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/AssemblyMetadataExtractor.cs +2 -1
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +2 -2
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +178 -176
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +2 -1
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/PackagesConfigBuildFile.cs +1 -0
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/ProjectBuildFile.cs +5 -4
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/CompatabilityChecker.cs +1 -0
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/FrameworkCompatibilityService.cs +10 -5
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/SupportedFrameworks.cs +16 -12
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs +18 -17
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectResolver.cs +7 -7
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +13 -20
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +9 -3
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +32 -16
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SdkPackageUpdater.cs +42 -22
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +32 -13
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/WebApplicationTargetsConditionPatcher.cs +47 -0
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/XmlFilePreAndPostProcessor.cs +55 -0
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/JsonHelper.cs +12 -9
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +49 -42
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +16 -3
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProcessExtensions.cs +6 -6
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/XmlExtensions.cs +11 -0
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/ProjectBuildFileTests.cs +18 -9
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/CompatibilityCheckerFacts.cs +2 -2
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/FrameworkCompatibilityServiceFacts.cs +7 -7
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/SupportedFrameworkFacts.cs +1 -1
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +9 -9
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorker.DirsProj.cs +81 -80
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +22 -9
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DotNetTools.cs +140 -104
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +25 -25
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Mixed.cs +8 -9
  37. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +198 -22
  38. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Sdk.cs +401 -399
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/JsonHelperTests.cs +17 -15
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +111 -42
  41. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterTests.cs +103 -87
  42. data/lib/dependabot/nuget/file_parser/project_file_parser.rb +45 -19
  43. data/lib/dependabot/nuget/file_parser.rb +21 -3
  44. data/lib/dependabot/nuget/file_updater.rb +42 -6
  45. data/lib/dependabot/nuget/native_helpers.rb +27 -8
  46. data/lib/dependabot/nuget/nuget_client.rb +66 -23
  47. data/lib/dependabot/nuget/nuget_config_credential_helpers.rb +7 -3
  48. data/lib/dependabot/nuget/update_checker/compatibility_checker.rb +63 -59
  49. data/lib/dependabot/nuget/update_checker/dependency_finder.rb +2 -2
  50. data/lib/dependabot/nuget/update_checker/nupkg_fetcher.rb +1 -1
  51. data/lib/dependabot/nuget/update_checker/nuspec_fetcher.rb +22 -17
  52. data/lib/dependabot/nuget/update_checker/repository_finder.rb +292 -270
  53. data/lib/dependabot/nuget/update_checker/tfm_comparer.rb +11 -13
  54. data/lib/dependabot/nuget/update_checker/tfm_finder.rb +80 -82
  55. data/lib/dependabot/nuget/update_checker/version_finder.rb +3 -2
  56. data/lib/dependabot/nuget/version.rb +18 -7
  57. data/lib/dependabot/nuget.rb +0 -2
  58. metadata +7 -5
@@ -1,4 +1,5 @@
1
1
  using System;
2
+ using System.Text.Json;
2
3
  using System.Text.Json.Nodes;
3
4
 
4
5
  using NuGetUpdater.Core.Utilities;
@@ -35,7 +36,7 @@ internal abstract class JsonBuildFile : BuildFile<string>
35
36
  {
36
37
  return JsonHelper.ParseNode(Contents);
37
38
  }
38
- catch (System.Text.Json.JsonException ex)
39
+ catch (JsonException ex)
39
40
  {
40
41
  // We can't police that people have legal JSON files.
41
42
  // If they don't, we just return null.
@@ -11,6 +11,7 @@ internal sealed class PackagesConfigBuildFile : XmlBuildFile
11
11
  {
12
12
  public static PackagesConfigBuildFile Open(string repoRootPath, string path)
13
13
  => Parse(repoRootPath, path, File.ReadAllText(path));
14
+
14
15
  public static PackagesConfigBuildFile Parse(string repoRootPath, string path, string xml)
15
16
  => new(repoRootPath, path, Parser.ParseText(xml));
16
17
 
@@ -11,6 +11,7 @@ internal sealed class ProjectBuildFile : XmlBuildFile
11
11
  {
12
12
  public static ProjectBuildFile Open(string repoRootPath, string path)
13
13
  => Parse(repoRootPath, path, File.ReadAllText(path));
14
+
14
15
  public static ProjectBuildFile Parse(string repoRootPath, string path, string xml)
15
16
  => new(repoRootPath, path, Parser.ParseText(xml));
16
17
 
@@ -31,9 +32,9 @@ internal sealed class ProjectBuildFile : XmlBuildFile
31
32
  .SelectMany(e => e.Elements);
32
33
 
33
34
  public IEnumerable<IXmlElementSyntax> PackageItemNodes => ItemNodes.Where(e =>
34
- e.Name.Equals("PackageReference", StringComparison.OrdinalIgnoreCase) ||
35
- e.Name.Equals("GlobalPackageReference", StringComparison.OrdinalIgnoreCase) ||
36
- e.Name.Equals("PackageVersion", StringComparison.OrdinalIgnoreCase));
35
+ e.Name.Equals("PackageReference", StringComparison.OrdinalIgnoreCase) ||
36
+ e.Name.Equals("GlobalPackageReference", StringComparison.OrdinalIgnoreCase) ||
37
+ e.Name.Equals("PackageVersion", StringComparison.OrdinalIgnoreCase));
37
38
 
38
39
  public IEnumerable<Dependency> GetDependencies() => PackageItemNodes
39
40
  .Select(GetDependency)
@@ -42,7 +43,7 @@ internal sealed class ProjectBuildFile : XmlBuildFile
42
43
  private static Dependency? GetDependency(IXmlElementSyntax element)
43
44
  {
44
45
  var name = element.GetAttributeOrSubElementValue("Include", StringComparison.OrdinalIgnoreCase)
45
- ?? element.GetAttributeOrSubElementValue("Update", StringComparison.OrdinalIgnoreCase);
46
+ ?? element.GetAttributeOrSubElementValue("Update", StringComparison.OrdinalIgnoreCase);
46
47
  if (name is null || name.StartsWith("@("))
47
48
  {
48
49
  return null;
@@ -33,6 +33,7 @@ public class CompatibilityChecker
33
33
  // effort by including just the platform.
34
34
  framework = new NuGetFramework(framework.Framework, framework.Version, framework.Platform, FrameworkConstants.EmptyVersion);
35
35
  }
36
+
36
37
  return framework;
37
38
  }
38
39
  }
@@ -5,6 +5,7 @@ using System;
5
5
  using System.Collections.Generic;
6
6
 
7
7
  using NuGet.Frameworks;
8
+
8
9
  using NuGetGallery.Frameworks;
9
10
 
10
11
  namespace NuGetUpdater.Core.FrameworkChecker;
@@ -15,7 +16,7 @@ public class FrameworkCompatibilityService
15
16
  private static readonly IReadOnlyList<NuGetFramework> AllSupportedFrameworks = SupportedFrameworks.AllSupportedNuGetFrameworks;
16
17
  private static readonly IReadOnlyDictionary<NuGetFramework, ISet<NuGetFramework>> CompatibilityMatrix = GetCompatibilityMatrix();
17
18
 
18
- public ISet<NuGetFramework> GetCompatibleFrameworks(IEnumerable<NuGetFramework> packageFrameworks)
19
+ public ISet<NuGetFramework> GetCompatibleFrameworks(IEnumerable<NuGetFramework>? packageFrameworks)
19
20
  {
20
21
  if (packageFrameworks == null)
21
22
  {
@@ -63,10 +64,14 @@ public class FrameworkCompatibilityService
63
64
  }
64
65
  }
65
66
 
66
- matrix.Add(SupportedFrameworks.Net60Windows7,
67
- new HashSet<NuGetFramework>() {
68
- SupportedFrameworks.Net60Windows, SupportedFrameworks.Net60Windows7,
69
- SupportedFrameworks.Net70Windows, SupportedFrameworks.Net70Windows7 });
67
+ matrix.Add(
68
+ SupportedFrameworks.Net60Windows7,
69
+ new HashSet<NuGetFramework>
70
+ {
71
+ SupportedFrameworks.Net60Windows, SupportedFrameworks.Net60Windows7,
72
+ SupportedFrameworks.Net70Windows, SupportedFrameworks.Net70Windows7
73
+ }
74
+ );
70
75
 
71
76
  return matrix;
72
77
  }
@@ -3,7 +3,9 @@
3
3
 
4
4
  using System;
5
5
  using System.Collections.Generic;
6
+
6
7
  using NuGet.Frameworks;
8
+
7
9
  using static NuGet.Frameworks.FrameworkConstants;
8
10
  using static NuGet.Frameworks.FrameworkConstants.CommonFrameworks;
9
11
 
@@ -42,7 +44,9 @@ namespace NuGetGallery.Frameworks
42
44
  public static readonly NuGetFramework Net70MacCatalyst = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "maccatalyst", EmptyVersion);
43
45
  public static readonly NuGetFramework Net70TvOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "tvos", EmptyVersion);
44
46
  public static readonly NuGetFramework Net70Windows = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version7, "windows", EmptyVersion);
47
+
45
48
  public static readonly NuGetFramework Net80 = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8); // https://github.com/NuGet/Engineering/issues/5112
49
+
46
50
  public static readonly NuGetFramework Net80Android = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "android", EmptyVersion);
47
51
  public static readonly NuGetFramework Net80Ios = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "ios", EmptyVersion);
48
52
  public static readonly NuGetFramework Net80MacOs = new NuGetFramework(FrameworkIdentifiers.NetCoreApp, Version8, "macos", EmptyVersion);
@@ -91,16 +95,16 @@ namespace NuGetGallery.Frameworks
91
95
  /// </summary>
92
96
  public static class TfmFilters
93
97
  {
94
- public static readonly List<NuGetFramework> NetTfms = new List<NuGetFramework>
95
- {
98
+ public static readonly List<NuGetFramework> NetTfms =
99
+ [
96
100
  Net80,
97
101
  Net70,
98
102
  Net60,
99
103
  Net50
100
- };
104
+ ];
101
105
 
102
- public static readonly List<NuGetFramework> NetCoreAppTfms = new List<NuGetFramework>
103
- {
106
+ public static readonly List<NuGetFramework> NetCoreAppTfms =
107
+ [
104
108
  NetCoreApp31,
105
109
  NetCoreApp30,
106
110
  NetCoreApp22,
@@ -108,10 +112,10 @@ namespace NuGetGallery.Frameworks
108
112
  NetCoreApp20,
109
113
  NetCoreApp11,
110
114
  NetCoreApp10
111
- };
115
+ ];
112
116
 
113
- public static readonly List<NuGetFramework> NetStandardTfms = new List<NuGetFramework>
114
- {
117
+ public static readonly List<NuGetFramework> NetStandardTfms =
118
+ [
115
119
  NetStandard21,
116
120
  NetStandard20,
117
121
  NetStandard16,
@@ -121,10 +125,10 @@ namespace NuGetGallery.Frameworks
121
125
  NetStandard12,
122
126
  NetStandard11,
123
127
  NetStandard10
124
- };
128
+ ];
125
129
 
126
- public static readonly List<NuGetFramework> NetFrameworkTfms = new List<NuGetFramework>
127
- {
130
+ public static readonly List<NuGetFramework> NetFrameworkTfms =
131
+ [
128
132
  Net481,
129
133
  Net48,
130
134
  Net472,
@@ -140,7 +144,7 @@ namespace NuGetGallery.Frameworks
140
144
  Net35,
141
145
  Net3,
142
146
  Net2
143
- };
147
+ ];
144
148
  }
145
149
  }
146
150
  }
@@ -7,11 +7,13 @@ using System.Linq;
7
7
  using System.Threading.Tasks;
8
8
  using System.Xml.Linq;
9
9
 
10
+ using CoreV2::NuGet.Runtime;
11
+
10
12
  using Microsoft.Language.Xml;
11
13
 
12
14
  using NuGet.ProjectManagement;
13
15
 
14
- using AssemblyBinding = CoreV2::NuGet.Runtime.AssemblyBinding;
16
+ using Runtime_AssemblyBinding = CoreV2::NuGet.Runtime.AssemblyBinding;
15
17
 
16
18
  namespace NuGetUpdater.Core;
17
19
 
@@ -150,7 +152,7 @@ internal static class BindingRedirectManager
150
152
 
151
153
  var path = Path.GetFileName(content);
152
154
  return (element.Name == "None" && string.Equals(path, "app.config", StringComparison.OrdinalIgnoreCase))
153
- || (element.Name == "Content" && string.Equals(path, "web.config", StringComparison.OrdinalIgnoreCase));
155
+ || (element.Name == "Content" && string.Equals(path, "web.config", StringComparison.OrdinalIgnoreCase));
154
156
  }
155
157
 
156
158
  static string GetConfigFileName(XmlDocumentSyntax document)
@@ -171,13 +173,13 @@ internal static class BindingRedirectManager
171
173
  {
172
174
  var frameworkVersion = GetFrameworkVersion(document);
173
175
  return $"""
174
- <?xml version="1.0" encoding="utf-8" ?>
175
- <configuration>
176
- <startup>
177
- <supportedRuntime version="v4.0" sku=".NETFramework,Version={frameworkVersion}" />
178
- </startup>
179
- </configuration>
180
- """;
176
+ <?xml version="1.0" encoding="utf-8" ?>
177
+ <configuration>
178
+ <startup>
179
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version={frameworkVersion}" />
180
+ </startup>
181
+ </configuration>
182
+ """;
181
183
  }
182
184
 
183
185
  static string? GetFrameworkVersion(XmlDocumentSyntax document)
@@ -190,7 +192,7 @@ internal static class BindingRedirectManager
190
192
  }
191
193
  }
192
194
 
193
- private static string AddBindingRedirects(ConfigurationFile configFile, IEnumerable<AssemblyBinding> bindingRedirects)
195
+ private static string AddBindingRedirects(ConfigurationFile configFile, IEnumerable<Runtime_AssemblyBinding> bindingRedirects)
194
196
  {
195
197
  // Do nothing if there are no binding redirects to add, bail out
196
198
  if (!bindingRedirects.Any())
@@ -261,7 +263,7 @@ internal static class BindingRedirectManager
261
263
 
262
264
  static void UpdateBindingRedirectElement(
263
265
  XElement existingDependentAssemblyElement,
264
- AssemblyBinding newBindingRedirect)
266
+ Runtime_AssemblyBinding newBindingRedirect)
265
267
  {
266
268
  var existingBindingRedirectElement = existingDependentAssemblyElement.Element(BindingRedirectName);
267
269
  // Since we've successfully parsed this node, it has to be valid and this child must exist.
@@ -287,12 +289,11 @@ internal static class BindingRedirectManager
287
289
  .Elements(DependentAssemblyName);
288
290
 
289
291
  // We're going to need to know which element is associated with what binding for removal
290
- var assemblyElementPairs = from dependentAssemblyElement in dependencyAssemblyElements
291
- select new
292
- {
293
- Binding = AssemblyBinding.Parse(dependentAssemblyElement),
294
- Element = dependentAssemblyElement
295
- };
292
+ var assemblyElementPairs = dependencyAssemblyElements.Select(dependentAssemblyElement => new
293
+ {
294
+ Binding = Runtime_AssemblyBinding.Parse(dependentAssemblyElement),
295
+ Element = dependentAssemblyElement
296
+ });
296
297
 
297
298
  // Return a mapping from binding to element
298
299
  return assemblyElementPairs.ToDictionary(p => (p.Binding.Name, p.Binding.PublicKeyToken), p => p.Element);
@@ -8,14 +8,14 @@ using System.Linq;
8
8
  using System.Reflection;
9
9
  using System.Text.RegularExpressions;
10
10
 
11
- using AssemblyBinding = CoreV2::NuGet.Runtime.AssemblyBinding;
12
- using IAssembly = CoreV2::NuGet.Runtime.IAssembly;
11
+ using Runtime_AssemblyBinding = CoreV2::NuGet.Runtime.AssemblyBinding;
12
+ using Runtime_IAssembly = CoreV2::NuGet.Runtime.IAssembly;
13
13
 
14
14
  namespace NuGetUpdater.Core;
15
15
 
16
16
  public static partial class BindingRedirectResolver
17
17
  {
18
- public static IEnumerable<AssemblyBinding> GetBindingRedirects(string projectPath, IEnumerable<string> includes)
18
+ public static IEnumerable<Runtime_AssemblyBinding> GetBindingRedirects(string projectPath, IEnumerable<string> includes)
19
19
  {
20
20
  var directoryPath = Path.GetDirectoryName(projectPath);
21
21
  if (directoryPath is null)
@@ -27,7 +27,7 @@ public static partial class BindingRedirectResolver
27
27
  {
28
28
  if (TryParseIncludesString(include, out var assemblyInfo))
29
29
  {
30
- yield return new AssemblyBinding(assemblyInfo);
30
+ yield return new Runtime_AssemblyBinding(assemblyInfo);
31
31
  }
32
32
  }
33
33
 
@@ -63,9 +63,9 @@ public static partial class BindingRedirectResolver
63
63
  private static readonly Regex IncludesRegex = IncludesPattern();
64
64
 
65
65
  /// <summary>
66
- /// Wraps systme<see cref="Assembly"/> type in the nuget interface <see cref="IAssembly"/> to interop with nuget apis
66
+ /// Wraps system<see cref="Assembly"/> type in the nuget interface <see cref="NuGet.Runtime.IAssembly"/> to interop with nuget apis
67
67
  /// </summary>
68
- private class AssemblyWrapper : IAssembly
68
+ private class AssemblyWrapper : Runtime_IAssembly
69
69
  {
70
70
  public AssemblyWrapper(string name, Version version, string? publicKeyToken = null, string? culture = null)
71
71
  {
@@ -79,7 +79,7 @@ public static partial class BindingRedirectResolver
79
79
  public Version Version { get; }
80
80
  public string? PublicKeyToken { get; }
81
81
  public string? Culture { get; }
82
- public IEnumerable<IAssembly> ReferencedAssemblies { get; } = Enumerable.Empty<AssemblyWrapper>();
82
+ public IEnumerable<Runtime_IAssembly> ReferencedAssemblies { get; } = Enumerable.Empty<AssemblyWrapper>();
83
83
  }
84
84
 
85
85
  [GeneratedRegex("(?<key>\\w+)=(?<value>[^,]+)")]
@@ -1,27 +1,27 @@
1
1
  using System;
2
2
  using System.Collections.Immutable;
3
- using System.IO;
4
3
  using System.Linq;
5
4
  using System.Threading.Tasks;
6
5
 
7
6
  namespace NuGetUpdater.Core;
8
7
 
9
- internal static partial class DotNetToolsJsonUpdater
8
+ internal static class DotNetToolsJsonUpdater
10
9
  {
11
- public static async Task UpdateDependencyAsync(string repoRootPath, string dependencyName, string previousDependencyVersion, string newDependencyVersion, Logger logger)
10
+ public static async Task UpdateDependencyAsync(string repoRootPath, string workspacePath, string dependencyName, string previousDependencyVersion, string newDependencyVersion,
11
+ Logger logger)
12
12
  {
13
- var buildFiles = LoadBuildFiles(repoRootPath, logger);
13
+ var buildFiles = LoadBuildFiles(repoRootPath, workspacePath, logger);
14
14
  if (buildFiles.Length == 0)
15
15
  {
16
- logger.Log($" No dotnet-tools.json files found.");
16
+ logger.Log(" No dotnet-tools.json files found.");
17
17
  return;
18
18
  }
19
19
 
20
- logger.Log($" Updating dotnet-tools.json files.");
20
+ logger.Log(" Updating dotnet-tools.json files.");
21
21
 
22
22
 
23
23
  var filesToUpdate = buildFiles.Where(f =>
24
- f.GetDependencies().Any(d => d.Name.Equals(dependencyName, StringComparison.OrdinalIgnoreCase)))
24
+ f.GetDependencies().Any(d => d.Name.Equals(dependencyName, StringComparison.OrdinalIgnoreCase)))
25
25
  .ToImmutableArray();
26
26
  if (filesToUpdate.Length == 0)
27
27
  {
@@ -39,7 +39,7 @@ internal static partial class DotNetToolsJsonUpdater
39
39
  if (toolObject is not null &&
40
40
  toolObject["version"]?.GetValue<string>() == previousDependencyVersion)
41
41
  {
42
- buildFile.UpdateProperty(new[] { "tools", dependencyName, "version" }, newDependencyVersion);
42
+ buildFile.UpdateProperty(["tools", dependencyName, "version"], newDependencyVersion);
43
43
 
44
44
  if (await buildFile.SaveAsync())
45
45
  {
@@ -49,18 +49,11 @@ internal static partial class DotNetToolsJsonUpdater
49
49
  }
50
50
  }
51
51
 
52
- private static ImmutableArray<DotNetToolsJsonBuildFile> LoadBuildFiles(string repoRootPath, Logger logger)
52
+ private static ImmutableArray<DotNetToolsJsonBuildFile> LoadBuildFiles(string repoRootPath, string workspacePath, Logger logger)
53
53
  {
54
- var options = new EnumerationOptions()
55
- {
56
- RecurseSubdirectories = true,
57
- MatchType = MatchType.Win32,
58
- AttributesToSkip = 0,
59
- IgnoreInaccessible = false,
60
- MatchCasing = MatchCasing.CaseInsensitive,
61
- };
62
- return Directory.EnumerateFiles(repoRootPath, "dotnet-tools.json", options)
63
- .Select(path => DotNetToolsJsonBuildFile.Open(repoRootPath, path, logger))
64
- .ToImmutableArray();
54
+ var dotnetToolsJsonPath = PathHelper.GetFileInDirectoryOrParent(workspacePath, repoRootPath, "./.config/dotnet-tools.json");
55
+ return dotnetToolsJsonPath is not null
56
+ ? [DotNetToolsJsonBuildFile.Open(repoRootPath, dotnetToolsJsonPath, logger)]
57
+ : [];
65
58
  }
66
59
  }
@@ -5,9 +5,15 @@ using System.Threading.Tasks;
5
5
 
6
6
  namespace NuGetUpdater.Core;
7
7
 
8
- internal static partial class GlobalJsonUpdater
8
+ internal static class GlobalJsonUpdater
9
9
  {
10
- public static async Task UpdateDependencyAsync(string repoRootPath, string globalJsonPath, string dependencyName, string previousDependencyVersion, string newDependencyVersion, Logger logger)
10
+ public static async Task UpdateDependencyAsync(
11
+ string repoRootPath,
12
+ string globalJsonPath,
13
+ string dependencyName,
14
+ string previousDependencyVersion,
15
+ string newDependencyVersion,
16
+ Logger logger)
11
17
  {
12
18
  if (!File.Exists(globalJsonPath))
13
19
  {
@@ -29,7 +35,7 @@ internal static partial class GlobalJsonUpdater
29
35
  if (globalJsonFile.MSBuildSdks?.TryGetPropertyValue(dependencyName, out var version) != true
30
36
  || version?.GetValue<string>() is not string versionString)
31
37
  {
32
- logger.Log($" Unable to determine dependency version.");
38
+ logger.Log(" Unable to determine dependency version.");
33
39
  return;
34
40
  }
35
41
 
@@ -4,15 +4,28 @@ using System.IO;
4
4
  using System.Linq;
5
5
  using System.Text;
6
6
  using System.Threading.Tasks;
7
- using System.Xml.Linq;
8
7
 
9
8
  using Microsoft.Language.Xml;
10
9
 
10
+ using NuGet.CommandLine;
11
+
12
+ using NuGetUpdater.Core.Updater;
13
+
14
+ using Console = System.Console;
15
+
11
16
  namespace NuGetUpdater.Core;
12
17
 
13
18
  internal static class PackagesConfigUpdater
14
19
  {
15
- public static async Task UpdateDependencyAsync(string repoRootPath, string projectPath, string dependencyName, string previousDependencyVersion, string newDependencyVersion, bool isTransitive, Logger logger)
20
+ public static async Task UpdateDependencyAsync(
21
+ string repoRootPath,
22
+ string projectPath,
23
+ string dependencyName,
24
+ string previousDependencyVersion,
25
+ string newDependencyVersion,
26
+ bool isTransitive,
27
+ Logger logger
28
+ )
16
29
  {
17
30
  logger.Log($" Found {NuGetHelper.PackagesConfigFileName}; running with NuGet.exe");
18
31
 
@@ -35,18 +48,18 @@ internal static class PackagesConfigUpdater
35
48
  var packagesDirectory = PathHelper.JoinPath(projectDirectory, packagesSubDirectory);
36
49
  Directory.CreateDirectory(packagesDirectory);
37
50
 
38
- var args = new List<string>()
39
- {
40
- "update",
41
- packagesConfigPath,
42
- "-Id",
43
- dependencyName,
44
- "-Version",
45
- newDependencyVersion,
46
- "-RepositoryPath",
47
- packagesDirectory,
48
- "-NonInteractive",
49
- };
51
+ var args = new List<string>
52
+ {
53
+ "update",
54
+ packagesConfigPath,
55
+ "-Id",
56
+ dependencyName,
57
+ "-Version",
58
+ newDependencyVersion,
59
+ "-RepositoryPath",
60
+ packagesDirectory,
61
+ "-NonInteractive",
62
+ };
50
63
 
51
64
  logger.Log(" Finding MSBuild...");
52
65
  var msbuildDirectory = MSBuildHelper.MSBuildPath;
@@ -56,7 +69,10 @@ internal static class PackagesConfigUpdater
56
69
  args.Add(msbuildDirectory); // e.g., /usr/share/dotnet/sdk/7.0.203
57
70
  }
58
71
 
59
- RunNuget(args, packagesDirectory, logger);
72
+ using (new WebApplicationTargetsConditionPatcher(projectPath))
73
+ {
74
+ RunNuget(args, packagesDirectory, logger);
75
+ }
60
76
 
61
77
  projectBuildFile = ProjectBuildFile.Open(repoRootPath, projectPath);
62
78
  projectBuildFile.NormalizeDirectorySeparatorsInProject();
@@ -84,7 +100,7 @@ internal static class PackagesConfigUpdater
84
100
  logger.Log($" Running NuGet.exe with args: {string.Join(" ", args)}");
85
101
 
86
102
  Environment.CurrentDirectory = packagesDirectory;
87
- var result = NuGet.CommandLine.Program.Main(args.ToArray());
103
+ var result = Program.Main(args.ToArray());
88
104
  var fullOutput = outputBuilder.ToString();
89
105
  logger.Log($" Result: {result}");
90
106
  logger.Log($" Output:\n{fullOutput}");
@@ -5,16 +5,23 @@ using System.IO;
5
5
  using System.Linq;
6
6
  using System.Threading.Tasks;
7
7
 
8
- using Microsoft.Build.Evaluation;
9
8
  using Microsoft.Language.Xml;
10
9
 
11
10
  using NuGet.Versioning;
12
11
 
13
12
  namespace NuGetUpdater.Core;
14
13
 
15
- internal static partial class SdkPackageUpdater
14
+ internal static class SdkPackageUpdater
16
15
  {
17
- public static async Task UpdateDependencyAsync(string repoRootPath, string projectPath, string dependencyName, string previousDependencyVersion, string newDependencyVersion, bool isTransitive, Logger logger)
16
+ public static async Task UpdateDependencyAsync(
17
+ string repoRootPath,
18
+ string projectPath,
19
+ string dependencyName,
20
+ string previousDependencyVersion,
21
+ string newDependencyVersion,
22
+ bool isTransitive,
23
+ Logger logger
24
+ )
18
25
  {
19
26
  // SDK-style project, modify the XML directly
20
27
  logger.Log(" Running for SDK-style project");
@@ -74,7 +81,7 @@ internal static partial class SdkPackageUpdater
74
81
  // stop update process if we find conflicting package versions
75
82
  var conflictingPackageVersionsFound = false;
76
83
  var packagesAndVersions = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
77
- foreach (var (tfm, dependencies) in tfmsAndDependencies)
84
+ foreach (var (_, dependencies) in tfmsAndDependencies)
78
85
  {
79
86
  foreach (var (packageName, packageVersion, _, _, _, _) in dependencies)
80
87
  {
@@ -118,7 +125,7 @@ internal static partial class SdkPackageUpdater
118
125
  }
119
126
  else
120
127
  {
121
- await UpdateTopLevelDepdendencyAsync(buildFiles, dependencyName, previousDependencyVersion, newDependencyVersion, packagesAndVersions, logger);
128
+ UpdateTopLevelDepdendency(buildFiles, dependencyName, previousDependencyVersion, newDependencyVersion, packagesAndVersions, logger);
122
129
  }
123
130
 
124
131
  var updatedTopLevelDependencies = MSBuildHelper.GetTopLevelPackageDependenyInfos(buildFiles);
@@ -239,7 +246,14 @@ internal static partial class SdkPackageUpdater
239
246
  }
240
247
  }
241
248
 
242
- private static async Task UpdateTopLevelDepdendencyAsync(ImmutableArray<ProjectBuildFile> buildFiles, string dependencyName, string previousDependencyVersion, string newDependencyVersion, Dictionary<string, string> packagesAndVersions, Logger logger)
249
+ private static void UpdateTopLevelDepdendency(
250
+ ImmutableArray<ProjectBuildFile> buildFiles,
251
+ string dependencyName,
252
+ string previousDependencyVersion,
253
+ string newDependencyVersion,
254
+ IDictionary<string, string> packagesAndVersions,
255
+ Logger logger
256
+ )
243
257
  {
244
258
  var result = TryUpdateDependencyVersion(buildFiles, dependencyName, previousDependencyVersion, newDependencyVersion, logger);
245
259
  if (result == UpdateResult.NotFound)
@@ -254,7 +268,12 @@ internal static partial class SdkPackageUpdater
254
268
  }
255
269
  }
256
270
 
257
- private static UpdateResult TryUpdateDependencyVersion(ImmutableArray<ProjectBuildFile> buildFiles, string dependencyName, string? previousDependencyVersion, string newDependencyVersion, Logger logger)
271
+ private static UpdateResult TryUpdateDependencyVersion(
272
+ ImmutableArray<ProjectBuildFile> buildFiles,
273
+ string dependencyName,
274
+ string? previousDependencyVersion,
275
+ string newDependencyVersion,
276
+ Logger logger)
258
277
  {
259
278
  var foundCorrect = false;
260
279
  var foundUnsupported = false;
@@ -275,9 +294,9 @@ internal static partial class SdkPackageUpdater
275
294
  foreach (var packageNode in packageNodes)
276
295
  {
277
296
  var versionAttribute = packageNode.GetAttribute("Version", StringComparison.OrdinalIgnoreCase)
278
- ?? packageNode.GetAttribute("VersionOverride", StringComparison.OrdinalIgnoreCase);
297
+ ?? packageNode.GetAttribute("VersionOverride", StringComparison.OrdinalIgnoreCase);
279
298
  var versionElement = packageNode.Elements.FirstOrDefault(e => e.Name.Equals("Version", StringComparison.OrdinalIgnoreCase))
280
- ?? packageNode.Elements.FirstOrDefault(e => e.Name.Equals("VersionOverride", StringComparison.OrdinalIgnoreCase));
299
+ ?? packageNode.Elements.FirstOrDefault(e => e.Name.Equals("VersionOverride", StringComparison.OrdinalIgnoreCase));
281
300
  if (versionAttribute is not null)
282
301
  {
283
302
  // Is this the case where version is specified with property substitution?
@@ -373,31 +392,29 @@ internal static partial class SdkPackageUpdater
373
392
  else
374
393
  {
375
394
  // We weren't able to find the version node. Central package management?
376
- logger.Log($" Found package reference but was unable to locate version information.");
377
- continue;
395
+ logger.Log(" Found package reference but was unable to locate version information.");
378
396
  }
379
397
  }
380
398
 
381
399
  if (updateNodes.Count > 0)
382
400
  {
383
401
  var updatedXml = buildFile.Contents
384
- .ReplaceNodes(updateNodes, (o, n) =>
402
+ .ReplaceNodes(updateNodes, (_, n) =>
385
403
  {
386
404
  if (n is XmlAttributeSyntax attributeSyntax)
387
405
  {
388
406
  return attributeSyntax.WithValue(attributeSyntax.Value.Replace(previousPackageVersion!, newDependencyVersion));
389
407
  }
390
- else if (n is XmlElementSyntax elementsSyntax)
408
+
409
+ if (n is XmlElementSyntax elementsSyntax)
391
410
  {
392
411
  var modifiedContent = elementsSyntax.GetContentValue().Replace(previousPackageVersion!, newDependencyVersion);
393
412
 
394
413
  var textSyntax = SyntaxFactory.XmlText(SyntaxFactory.Token(null, SyntaxKind.XmlTextLiteralToken, null, modifiedContent));
395
414
  return elementsSyntax.WithContent(SyntaxFactory.SingletonList(textSyntax));
396
415
  }
397
- else
398
- {
399
- throw new InvalidDataException($"Unsupported SyntaxType {n.GetType().Name} marked for update");
400
- }
416
+
417
+ throw new InvalidDataException($"Unsupported SyntaxType {n.GetType().Name} marked for update");
401
418
  });
402
419
  buildFile.Update(updatedXml);
403
420
  updateWasPerformed = true;
@@ -489,10 +506,13 @@ internal static partial class SdkPackageUpdater
489
506
  : UpdateResult.NotFound;
490
507
  }
491
508
 
492
- private static IEnumerable<IXmlElementSyntax> FindPackageNodes(ProjectBuildFile buildFile, string packageName)
493
- {
494
- return buildFile.PackageItemNodes.Where(e =>
495
- string.Equals(e.GetAttributeOrSubElementValue("Include", StringComparison.OrdinalIgnoreCase) ?? e.GetAttributeOrSubElementValue("Update", StringComparison.OrdinalIgnoreCase), packageName, StringComparison.OrdinalIgnoreCase) &&
509
+ private static IEnumerable<IXmlElementSyntax> FindPackageNodes(
510
+ ProjectBuildFile buildFile,
511
+ string packageName)
512
+ => buildFile.PackageItemNodes.Where(e =>
513
+ string.Equals(
514
+ e.GetAttributeOrSubElementValue("Include", StringComparison.OrdinalIgnoreCase) ?? e.GetAttributeOrSubElementValue("Update", StringComparison.OrdinalIgnoreCase),
515
+ packageName,
516
+ StringComparison.OrdinalIgnoreCase) &&
496
517
  (e.GetAttributeOrSubElementValue("Version", StringComparison.OrdinalIgnoreCase) ?? e.GetAttributeOrSubElementValue("VersionOverride", StringComparison.OrdinalIgnoreCase)) is not null);
497
- }
498
518
  }