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
@@ -36,6 +36,14 @@ internal static class SdkProjectDiscovery
36
36
  "NETStandard.Library"
37
37
  };
38
38
 
39
+ // these are additional files that are relevant to the project and need to be reported
40
+ private static readonly HashSet<string> AdditionalFileNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
41
+ {
42
+ "packages.config",
43
+ "app.config",
44
+ "web.config",
45
+ };
46
+
39
47
  public static async Task<ImmutableArray<ProjectDiscoveryResult>> DiscoverAsync(string repoRootPath, string workspacePath, string startingProjectPath, ExperimentsManager experimentsManager, ILogger logger)
40
48
  {
41
49
  if (experimentsManager.UseDirectDiscovery)
@@ -73,6 +81,9 @@ internal static class SdkProjectDiscovery
73
81
  Dictionary<string, HashSet<string>> referencedProjects = new(PathComparer.Instance);
74
82
  // projectPath, referencedProjects
75
83
 
84
+ Dictionary<string, HashSet<string>> additionalFiles = new(PathComparer.Instance);
85
+ // projectPath, additionalFiles
86
+
76
87
  var tfms = await MSBuildHelper.GetTargetFrameworkValuesFromProject(repoRootPath, startingProjectPath, logger);
77
88
  foreach (var tfm in tfms)
78
89
  {
@@ -106,7 +117,7 @@ internal static class SdkProjectDiscovery
106
117
  if (exitCode != 0)
107
118
  {
108
119
  // log error, but still try to resolve what we can
109
- logger.Log($" Error determining dependencies from `{startingProjectPath}`:\nSTDOUT:\n{stdOut}\nSTDERR:\n{stdErr}");
120
+ logger.Warn($" Error determining dependencies from `{startingProjectPath}`:\nSTDOUT:\n{stdOut}\nSTDERR:\n{stdErr}");
110
121
  }
111
122
 
112
123
  var buildRoot = BinaryLog.ReadBuild(binLogPath);
@@ -154,17 +165,39 @@ internal static class SdkProjectDiscovery
154
165
  case NamedNode namedNode when namedNode is AddItem or RemoveItem:
155
166
  ProcessResolvedPackageReference(namedNode, packagesPerProject, topLevelPackagesPerProject);
156
167
 
157
- // maintain list of project references
158
- if (namedNode is AddItem addItem && addItem.Name == "ProjectReference")
168
+ if (namedNode is AddItem addItem)
159
169
  {
160
- var projectEvaluation = GetNearestProjectEvaluation(addItem);
161
- if (projectEvaluation is not null)
170
+ // maintain list of project references
171
+ if (addItem.Name.Equals("ProjectReference", StringComparison.OrdinalIgnoreCase))
172
+ {
173
+ var projectEvaluation = GetNearestProjectEvaluation(addItem);
174
+ if (projectEvaluation is not null)
175
+ {
176
+ foreach (var referencedProject in addItem.Children.OfType<Item>())
177
+ {
178
+ var referencedProjectPaths = referencedProjects.GetOrAdd(projectEvaluation.ProjectFile, () => new(PathComparer.Instance));
179
+ var referencedProjectPath = new FileInfo(Path.Combine(Path.GetDirectoryName(projectEvaluation.ProjectFile)!, referencedProject.Name)).FullName;
180
+ referencedProjectPaths.Add(referencedProjectPath);
181
+ }
182
+ }
183
+ }
184
+
185
+ // maintain list of additional files
186
+ if (addItem.Name.Equals("None", StringComparison.OrdinalIgnoreCase) ||
187
+ addItem.Name.Equals("Content", StringComparison.OrdinalIgnoreCase))
162
188
  {
163
- foreach (var referencedProject in addItem.Children.OfType<Item>())
189
+ var projectEvaluation = GetNearestProjectEvaluation(addItem);
190
+ if (projectEvaluation is not null)
164
191
  {
165
- var referencedProjectPaths = referencedProjects.GetOrAdd(projectEvaluation.ProjectFile, () => new(PathComparer.Instance));
166
- var referencedProjectPath = new FileInfo(Path.Combine(Path.GetDirectoryName(projectEvaluation.ProjectFile)!, referencedProject.Name)).FullName;
167
- referencedProjectPaths.Add(referencedProjectPath);
192
+ foreach (var additionalItem in addItem.Children.OfType<Item>())
193
+ {
194
+ if (AdditionalFileNames.Contains(additionalItem.Name))
195
+ {
196
+ var additionalFilesForProject = additionalFiles.GetOrAdd(projectEvaluation.ProjectFile, () => new(PathComparer.Instance));
197
+ var additionalFilePath = new FileInfo(Path.Combine(Path.GetDirectoryName(projectEvaluation.ProjectFile)!, additionalItem.Name)).FullName;
198
+ additionalFilesForProject.Add(additionalFilePath);
199
+ }
200
+ }
168
201
  }
169
202
  }
170
203
  }
@@ -220,11 +253,18 @@ internal static class SdkProjectDiscovery
220
253
  .Select(pkvp => new Property(pkvp.Key, pkvp.Value, Path.GetRelativePath(repoRootPath, projectPath).NormalizePathToUnix()))
221
254
  .OrderBy(p => p.Name)
222
255
  .ToImmutableArray();
223
- var referenced = referencedProjects.GetOrAdd(projectPath, () => new(StringComparer.OrdinalIgnoreCase))
256
+ var referenced = referencedProjects.GetOrAdd(projectPath, () => new(PathComparer.Instance))
224
257
  .Select(p => Path.GetRelativePath(projectFullDirectory, p).NormalizePathToUnix())
225
258
  .OrderBy(p => p)
226
259
  .ToImmutableArray();
227
- var imported = importedFiles.GetOrAdd(projectPath, () => new(StringComparer.OrdinalIgnoreCase))
260
+ var imported = importedFiles.GetOrAdd(projectPath, () => new(PathComparer.Instance))
261
+ .Select(p => Path.GetRelativePath(projectFullDirectory, p))
262
+ .Select(p => p.NormalizePathToUnix())
263
+ .OrderBy(p => p)
264
+ .ToImmutableArray();
265
+ var additionalFromLocation = ProjectHelper.GetAdditionalFilesFromProjectLocation(projectPath, ProjectHelper.PathFormat.Full);
266
+ var additional = additionalFiles.GetOrAdd(projectPath, () => new(PathComparer.Instance))
267
+ .Concat(additionalFromLocation)
228
268
  .Select(p => Path.GetRelativePath(projectFullDirectory, p))
229
269
  .Select(p => p.NormalizePathToUnix())
230
270
  .OrderBy(p => p)
@@ -238,6 +278,7 @@ internal static class SdkProjectDiscovery
238
278
  Properties = properties,
239
279
  ReferencedProjectPaths = referenced,
240
280
  ImportedFiles = imported,
281
+ AdditionalFiles = additional,
241
282
  };
242
283
  }).ToImmutableArray();
243
284
  return projectDiscoveryResults;
@@ -448,6 +489,7 @@ internal static class SdkProjectDiscovery
448
489
  Path.Join(Path.GetDirectoryName(buildFile.Path), "obj"),
449
490
  };
450
491
  var projectDirectory = Path.GetDirectoryName(buildFile.Path)!;
492
+ var additionalFiles = ProjectHelper.GetAllAdditionalFilesFromProject(buildFile.Path, ProjectHelper.PathFormat.Relative);
451
493
  results.Add(new()
452
494
  {
453
495
  FilePath = Path.GetRelativePath(workspacePath, buildFile.Path).NormalizePathToUnix(),
@@ -463,6 +505,7 @@ internal static class SdkProjectDiscovery
463
505
  .Where(b => !intermediateDirectories.Any(i => PathHelper.IsFileUnderDirectory(new DirectoryInfo(i), new FileInfo(b.Path))))
464
506
  .Select(b => Path.GetRelativePath(projectDirectory, b.Path).NormalizePathToUnix())
465
507
  .ToImmutableArray(),
508
+ AdditionalFiles = additionalFiles,
466
509
  });
467
510
  }
468
511
  }
@@ -7,7 +7,6 @@ public sealed record WorkspaceDiscoveryResult : NativeResult
7
7
  public required string Path { get; init; }
8
8
  public bool IsSuccess { get; init; } = true;
9
9
  public ImmutableArray<ProjectDiscoveryResult> Projects { get; init; }
10
- public ImmutableArray<string> ImportedFiles { get; init; } = [];
11
10
  public GlobalJsonDiscoveryResult? GlobalJson { get; init; }
12
11
  public DotNetToolsJsonDiscoveryResult? DotNetToolsJson { get; init; }
13
12
  }
@@ -37,8 +37,7 @@ public record ExperimentsManager
37
37
  }
38
38
  catch (JsonException ex)
39
39
  {
40
- // the following message has been specifically designed to match the format of `Dependabot.logger.info(...)` from Ruby
41
- logger.Log($"{DateTime.UtcNow:yyyy/MM/dd HH:mm:ss} INFO Error deserializing job file: {ex.ToString()}: {jobFileContent}");
40
+ logger.Info($"Error deserializing job file: {ex.ToString()}: {jobFileContent}");
42
41
  return new ExperimentsManager();
43
42
  }
44
43
  }
@@ -39,7 +39,7 @@ internal abstract class JsonBuildFile : BuildFile<string>
39
39
  {
40
40
  // We can't police that people have legal JSON files.
41
41
  // If they don't, we just return null.
42
- logger.Log($"Failed to parse JSON file: {RelativePath}, got {ex}");
42
+ logger.Warn($"Failed to parse JSON file: {RelativePath}, got {ex}");
43
43
  FailedToParse = true;
44
44
  return null;
45
45
  }
@@ -15,11 +15,11 @@ public class CompatibilityChecker
15
15
  var incompatibleFrameworks = projectFrameworks.Where(f => !compatibleFrameworks.Contains(f)).ToArray();
16
16
  if (incompatibleFrameworks.Length > 0)
17
17
  {
18
- logger.Log($"The package is not compatible. Incompatible project frameworks: {string.Join(", ", incompatibleFrameworks.Select(f => f.GetShortFolderName()))}");
18
+ logger.Warn($"The package is not compatible. Incompatible project frameworks: {string.Join(", ", incompatibleFrameworks.Select(f => f.GetShortFolderName()))}");
19
19
  return false;
20
20
  }
21
21
 
22
- logger.Log("The package is compatible.");
22
+ logger.Info("The package is compatible.");
23
23
  return true;
24
24
 
25
25
  static NuGetFramework ParseFramework(string tfm)
@@ -113,8 +113,8 @@ public class RunWorker
113
113
  {
114
114
  var discoveryResult = await _discoveryWorker.RunAsync(repoContentsPath.FullName, repoDirectory);
115
115
 
116
- _logger.Log("Discovery JSON content:");
117
- _logger.Log(JsonSerializer.Serialize(discoveryResult, DiscoveryWorker.SerializerOptions));
116
+ _logger.Info("Discovery JSON content:");
117
+ _logger.Info(JsonSerializer.Serialize(discoveryResult, DiscoveryWorker.SerializerOptions));
118
118
 
119
119
  // report dependencies
120
120
  var discoveredUpdatedDependencies = GetUpdatedDependencyListFromDiscovery(discoveryResult, repoContentsPath.FullName);
@@ -134,35 +134,28 @@ public class RunWorker
134
134
  });
135
135
 
136
136
  // track original contents for later handling
137
- async Task TrackOriginalContentsAsync(string directory, string fileName, string? replacementFileName = null)
137
+ async Task TrackOriginalContentsAsync(string directory, string fileName)
138
138
  {
139
- var repoFullPath = Path.Join(directory, fileName);
140
- if (replacementFileName is not null)
141
- {
142
- repoFullPath = Path.Join(Path.GetDirectoryName(repoFullPath)!, replacementFileName);
143
- }
144
-
145
- repoFullPath = repoFullPath.FullyNormalizedRootedPath();
139
+ var repoFullPath = Path.Join(directory, fileName).FullyNormalizedRootedPath();
146
140
  var localFullPath = Path.Join(repoContentsPath.FullName, repoFullPath);
147
-
148
- if (!File.Exists(localFullPath))
149
- {
150
- return;
151
- }
152
-
153
141
  var content = await File.ReadAllTextAsync(localFullPath);
154
142
  originalDependencyFileContents[repoFullPath] = content;
155
143
  }
156
144
 
157
145
  foreach (var project in discoveryResult.Projects)
158
146
  {
147
+ var projectDirectory = Path.GetDirectoryName(project.FilePath);
159
148
  await TrackOriginalContentsAsync(discoveryResult.Path, project.FilePath);
160
- await TrackOriginalContentsAsync(discoveryResult.Path, project.FilePath, replacementFileName: "packages.config");
149
+ foreach (var extraFile in project.ImportedFiles.Concat(project.AdditionalFiles))
150
+ {
151
+ var extraFilePath = Path.Join(projectDirectory, extraFile);
152
+ await TrackOriginalContentsAsync(discoveryResult.Path, extraFilePath);
153
+ }
161
154
  // TODO: include global.json, etc.
162
155
  }
163
156
 
164
157
  // do update
165
- _logger.Log($"Running update in directory {repoDirectory}");
158
+ _logger.Info($"Running update in directory {repoDirectory}");
166
159
  foreach (var project in discoveryResult.Projects)
167
160
  {
168
161
  foreach (var dependency in project.Dependencies.Where(d => !d.IsTransitive))
@@ -192,13 +185,7 @@ public class RunWorker
192
185
  // TODO: log analysisResult
193
186
  if (analysisResult.CanUpdate)
194
187
  {
195
- var dependencyLocation = Path.Join(discoveryResult.Path, project.FilePath);
196
- if (dependency.Type == DependencyType.PackagesConfig)
197
- {
198
- dependencyLocation = Path.Join(Path.GetDirectoryName(dependencyLocation)!, "packages.config");
199
- }
200
-
201
- dependencyLocation = dependencyLocation.FullyNormalizedRootedPath();
188
+ var dependencyLocation = Path.Join(discoveryResult.Path, project.FilePath).FullyNormalizedRootedPath();
202
189
 
203
190
  // TODO: this is inefficient, but not likely causing a bottleneck
204
191
  var previousDependency = discoveredUpdatedDependencies.Dependencies
@@ -241,48 +228,46 @@ public class RunWorker
241
228
  }
242
229
 
243
230
  // create PR - we need to manually check file contents; we can't easily use `git status` in tests
244
- var updatedDependencyFiles = new List<DependencyFile>();
245
- async Task AddUpdatedFileIfDifferentAsync(string directory, string fileName, string? replacementFileName = null)
231
+ var updatedDependencyFiles = new Dictionary<string, DependencyFile>();
232
+ async Task AddUpdatedFileIfDifferentAsync(string directory, string fileName)
246
233
  {
247
- var repoFullPath = Path.Join(directory, fileName);
248
- if (replacementFileName is not null)
249
- {
250
- repoFullPath = Path.Join(Path.GetDirectoryName(repoFullPath)!, replacementFileName);
251
- }
252
-
253
- repoFullPath = repoFullPath.FullyNormalizedRootedPath();
254
- var localFullPath = Path.Join(repoContentsPath.FullName, repoFullPath);
255
-
256
- if (!File.Exists(localFullPath))
257
- {
258
- return;
259
- }
260
-
234
+ var repoFullPath = Path.Join(directory, fileName).FullyNormalizedRootedPath();
235
+ var localFullPath = Path.GetFullPath(Path.Join(repoContentsPath.FullName, repoFullPath));
261
236
  var originalContent = originalDependencyFileContents[repoFullPath];
262
237
  var updatedContent = await File.ReadAllTextAsync(localFullPath);
263
238
  if (updatedContent != originalContent)
264
239
  {
265
- updatedDependencyFiles.Add(new DependencyFile()
240
+ updatedDependencyFiles[localFullPath] = new DependencyFile()
266
241
  {
267
242
  Name = Path.GetFileName(repoFullPath),
268
243
  Directory = Path.GetDirectoryName(repoFullPath)!.NormalizePathToUnix(),
269
244
  Content = updatedContent,
270
- });
245
+ };
271
246
  }
272
247
  }
273
248
 
274
249
  foreach (var project in discoveryResult.Projects)
275
250
  {
276
251
  await AddUpdatedFileIfDifferentAsync(discoveryResult.Path, project.FilePath);
277
- await AddUpdatedFileIfDifferentAsync(discoveryResult.Path, project.FilePath, replacementFileName: "packages.config");
252
+ var projectDirectory = Path.GetDirectoryName(project.FilePath);
253
+ foreach (var extraFile in project.ImportedFiles.Concat(project.AdditionalFiles))
254
+ {
255
+ var extraFilePath = Path.Join(projectDirectory, extraFile);
256
+ await AddUpdatedFileIfDifferentAsync(discoveryResult.Path, extraFilePath);
257
+ }
258
+ // TODO: handle global.json, etc.
278
259
  }
279
260
 
280
261
  if (updatedDependencyFiles.Count > 0)
281
262
  {
263
+ var updatedDependencyFileList = updatedDependencyFiles
264
+ .OrderBy(kvp => kvp.Key)
265
+ .Select(kvp => kvp.Value)
266
+ .ToArray();
282
267
  var createPullRequest = new CreatePullRequest()
283
268
  {
284
269
  Dependencies = actualUpdatedDependencies.ToArray(),
285
- UpdatedDependencyFiles = updatedDependencyFiles.ToArray(),
270
+ UpdatedDependencyFiles = updatedDependencyFileList,
286
271
  BaseCommitSha = baseCommitSha,
287
272
  CommitMessage = "TODO: message",
288
273
  PrTitle = "TODO: title",
@@ -303,7 +288,7 @@ public class RunWorker
303
288
 
304
289
  var result = new RunResult()
305
290
  {
306
- Base64DependencyFiles = originalDependencyFileContents.Select(kvp =>
291
+ Base64DependencyFiles = originalDependencyFileContents.OrderBy(kvp => kvp.Key).Select(kvp =>
307
292
  {
308
293
  var fullPath = kvp.Key.FullyNormalizedRootedPath();
309
294
  return new DependencyFile()
@@ -339,14 +324,20 @@ public class RunWorker
339
324
  foreach (var project in discoveryResult.Projects)
340
325
  {
341
326
  var projectDirectory = Path.GetDirectoryName(project.FilePath);
342
- var pathToPackagesConfig = Path.Join(pathToContents, discoveryResult.Path, projectDirectory, "packages.config");
343
-
344
- if (File.Exists(pathToPackagesConfig))
327
+ foreach (var extraFile in project.ImportedFiles.Concat(project.AdditionalFiles))
345
328
  {
346
- auxiliaryFiles.Add(GetFullRepoPath(Path.Join(projectDirectory, "packages.config")));
329
+ var extraFileFullPath = Path.Join(projectDirectory, extraFile);
330
+ var extraFileRepoPath = GetFullRepoPath(extraFileFullPath);
331
+ auxiliaryFiles.Add(extraFileRepoPath);
347
332
  }
348
333
  }
349
334
 
335
+ var dependencyFiles = discoveryResult.Projects
336
+ .Select(p => GetFullRepoPath(p.FilePath))
337
+ .Concat(auxiliaryFiles)
338
+ .Distinct()
339
+ .OrderBy(p => p)
340
+ .ToArray();
350
341
  var updatedDependencyList = new UpdatedDependencyList()
351
342
  {
352
343
  Dependencies = discoveryResult.Projects.SelectMany(p =>
@@ -357,9 +348,7 @@ public class RunWorker
357
348
  Name = d.Name,
358
349
  Requirements = d.IsTransitive ? [] : [new ReportedRequirement()
359
350
  {
360
- File = d.Type == DependencyType.PackagesConfig
361
- ? Path.Join(Path.GetDirectoryName(GetFullRepoPath(p.FilePath))!, "packages.config").FullyNormalizedRootedPath()
362
- : GetFullRepoPath(p.FilePath),
351
+ File = GetFullRepoPath(p.FilePath),
363
352
  Requirement = d.Version!,
364
353
  Groups = ["dependencies"],
365
354
  }],
@@ -367,7 +356,7 @@ public class RunWorker
367
356
  }
368
357
  );
369
358
  }).ToArray(),
370
- DependencyFiles = discoveryResult.Projects.Select(p => GetFullRepoPath(p.FilePath)).Concat(auxiliaryFiles).ToArray(),
359
+ DependencyFiles = dependencyFiles,
371
360
  };
372
361
  return updatedDependencyList;
373
362
  }
@@ -8,6 +8,8 @@ using Microsoft.Language.Xml;
8
8
 
9
9
  using NuGet.ProjectManagement;
10
10
 
11
+ using NuGetUpdater.Core.Utilities;
12
+
11
13
  using Runtime_AssemblyBinding = CoreV2::NuGet.Runtime.AssemblyBinding;
12
14
 
13
15
  namespace NuGetUpdater.Core;
@@ -32,7 +34,7 @@ internal static class BindingRedirectManager
32
34
  /// <param name="updatedPackageVersion">The version of the package that was updated</param>
33
35
  public static async ValueTask UpdateBindingRedirectsAsync(ProjectBuildFile projectBuildFile, string updatedPackageName, string updatedPackageVersion)
34
36
  {
35
- var configFile = await TryGetRuntimeConfigurationFile(projectBuildFile);
37
+ var configFile = await TryGetRuntimeConfigurationFile(projectBuildFile.Path);
36
38
  if (configFile is null)
37
39
  {
38
40
  // no runtime config file so no need to add binding redirects
@@ -124,56 +126,24 @@ internal static class BindingRedirectManager
124
126
  }
125
127
  }
126
128
 
127
- private static async ValueTask<ConfigurationFile?> TryGetRuntimeConfigurationFile(ProjectBuildFile projectBuildFile)
129
+ private static async ValueTask<ConfigurationFile?> TryGetRuntimeConfigurationFile(string fullProjectPath)
128
130
  {
129
- var directoryPath = Path.GetDirectoryName(projectBuildFile.Path);
130
- if (directoryPath is null)
131
- {
132
- return null;
133
- }
134
-
135
- var configFile = projectBuildFile.ItemNodes
136
- .Where(IsConfigFile)
137
- .FirstOrDefault();
131
+ var additionalFiles = ProjectHelper.GetAdditionalFilesFromProjectContent(fullProjectPath, ProjectHelper.PathFormat.Full);
132
+ var configFilePath = additionalFiles
133
+ .FirstOrDefault(p =>
134
+ {
135
+ var fileName = Path.GetFileName(p);
136
+ return fileName.Equals(ProjectHelper.AppConfigFileName, StringComparison.OrdinalIgnoreCase)
137
+ || fileName.Equals(ProjectHelper.WebConfigFileName, StringComparison.OrdinalIgnoreCase);
138
+ });
138
139
 
139
- if (configFile is null)
140
+ if (configFilePath is null)
140
141
  {
141
142
  return null;
142
143
  }
143
144
 
144
- var configFilePath = Path.GetFullPath(Path.Combine(directoryPath, GetValue(configFile)));
145
145
  var configFileContents = await File.ReadAllTextAsync(configFilePath);
146
146
  return new ConfigurationFile(configFilePath, configFileContents, false);
147
-
148
- static string GetValue(IXmlElementSyntax element)
149
- {
150
- var content = element.GetAttributeValue("Include");
151
- if (!string.IsNullOrEmpty(content))
152
- {
153
- return content;
154
- }
155
-
156
- content = element.GetContentValue();
157
- if (!string.IsNullOrEmpty(content))
158
- {
159
- return content;
160
- }
161
-
162
- return string.Empty;
163
- }
164
-
165
- static bool IsConfigFile(IXmlElementSyntax element)
166
- {
167
- var content = GetValue(element);
168
- if (content is null)
169
- {
170
- return false;
171
- }
172
-
173
- var path = Path.GetFileName(content);
174
- return (element.Name == "None" && string.Equals(path, "app.config", StringComparison.OrdinalIgnoreCase))
175
- || (element.Name == "Content" && string.Equals(path, "web.config", StringComparison.OrdinalIgnoreCase));
176
- }
177
147
  }
178
148
 
179
149
  private static string AddBindingRedirects(ConfigurationFile configFile, IEnumerable<(Runtime_AssemblyBinding Binding, string AssemblyPath)> bindingRedirectsAndAssemblyPaths, string assemblyPathPrefix)
@@ -12,18 +12,18 @@ internal static class DotNetToolsJsonUpdater
12
12
  {
13
13
  if (!MSBuildHelper.TryGetDotNetToolsJsonPath(repoRootPath, workspacePath, out var dotnetToolsJsonPath))
14
14
  {
15
- logger.Log(" No dotnet-tools.json file found.");
15
+ logger.Info(" No dotnet-tools.json file found.");
16
16
  return;
17
17
  }
18
18
 
19
19
  var dotnetToolsJsonFile = DotNetToolsJsonBuildFile.Open(repoRootPath, dotnetToolsJsonPath, logger);
20
20
 
21
- logger.Log($" Updating [{dotnetToolsJsonFile.RelativePath}] file.");
21
+ logger.Info($" Updating [{dotnetToolsJsonFile.RelativePath}] file.");
22
22
 
23
23
  var containsDependency = dotnetToolsJsonFile.GetDependencies().Any(d => d.Name.Equals(dependencyName, StringComparison.OrdinalIgnoreCase));
24
24
  if (!containsDependency)
25
25
  {
26
- logger.Log($" Dependency [{dependencyName}] not found.");
26
+ logger.Info($" Dependency [{dependencyName}] not found.");
27
27
  return;
28
28
  }
29
29
 
@@ -39,7 +39,7 @@ internal static class DotNetToolsJsonUpdater
39
39
 
40
40
  if (await dotnetToolsJsonFile.SaveAsync())
41
41
  {
42
- logger.Log($" Saved [{dotnetToolsJsonFile.RelativePath}].");
42
+ logger.Info($" Saved [{dotnetToolsJsonFile.RelativePath}].");
43
43
  }
44
44
  }
45
45
  }
@@ -12,25 +12,25 @@ internal static class GlobalJsonUpdater
12
12
  {
13
13
  if (!MSBuildHelper.TryGetGlobalJsonPath(repoRootPath, workspacePath, out var globalJsonPath))
14
14
  {
15
- logger.Log(" No global.json file found.");
15
+ logger.Info(" No global.json file found.");
16
16
  return;
17
17
  }
18
18
 
19
19
  var globalJsonFile = GlobalJsonBuildFile.Open(repoRootPath, globalJsonPath, logger);
20
20
 
21
- logger.Log($" Updating [{globalJsonFile.RelativePath}] file.");
21
+ logger.Info($" Updating [{globalJsonFile.RelativePath}] file.");
22
22
 
23
23
  var containsDependency = globalJsonFile.GetDependencies().Any(d => d.Name.Equals(dependencyName, StringComparison.OrdinalIgnoreCase));
24
24
  if (!containsDependency)
25
25
  {
26
- logger.Log($" Dependency [{dependencyName}] not found.");
26
+ logger.Info($" Dependency [{dependencyName}] not found.");
27
27
  return;
28
28
  }
29
29
 
30
30
  if (globalJsonFile.MSBuildSdks?.TryGetPropertyValue(dependencyName, out var version) != true
31
31
  || version?.GetValue<string>() is not string versionString)
32
32
  {
33
- logger.Log(" Unable to determine dependency version.");
33
+ logger.Info(" Unable to determine dependency version.");
34
34
  return;
35
35
  }
36
36
 
@@ -43,7 +43,7 @@ internal static class GlobalJsonUpdater
43
43
 
44
44
  if (await globalJsonFile.SaveAsync())
45
45
  {
46
- logger.Log($" Saved [{globalJsonFile.RelativePath}].");
46
+ logger.Info($" Saved [{globalJsonFile.RelativePath}].");
47
47
  }
48
48
  }
49
49
  }
@@ -7,21 +7,13 @@ internal static class LockFileUpdater
7
7
  string projectPath,
8
8
  ILogger logger)
9
9
  {
10
- var projectDirectory = Path.GetDirectoryName(projectPath);
11
- var lockPath = Path.Combine(projectDirectory, "packages.lock.json");
12
- logger.Log($" Updating lock file");
13
- if (!File.Exists(lockPath))
14
- {
15
- logger.Log($" File [{Path.GetRelativePath(repoRootPath, lockPath)}] does not exist.");
16
- return;
17
- }
18
-
10
+ var projectDirectory = Path.GetDirectoryName(projectPath)!;
19
11
  await MSBuildHelper.SidelineGlobalJsonAsync(projectDirectory, repoRootPath, async () =>
20
12
  {
21
13
  var (exitCode, stdout, stderr) = await ProcessEx.RunAsync("dotnet", ["restore", "--force-evaluate", projectPath], workingDirectory: projectDirectory);
22
14
  if (exitCode != 0)
23
15
  {
24
- logger.Log($" Lock file update failed.\nSTDOUT:\n{stdout}\nSTDERR:\n{stderr}");
16
+ logger.Error($" Lock file update failed.\nSTDOUT:\n{stdout}\nSTDERR:\n{stderr}");
25
17
  }
26
18
  return (exitCode, stdout, stderr);
27
19
  }, logger, retainMSBuildSdks: true);