dependabot-nuget 0.321.3 → 0.322.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/lib/NuGetUpdater/Directory.Packages.props +22 -22
  3. data/helpers/lib/NuGetUpdater/DotNetPackageCorrelation.Cli/Program.cs +21 -7
  4. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/AnalyzeCommand.cs +19 -11
  5. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/CloneCommand.cs +19 -9
  6. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/DiscoverCommand.cs +21 -14
  7. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/FrameworkCheckCommand.cs +8 -5
  8. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/RunCommand.cs +29 -16
  9. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +20 -19
  10. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +2 -1
  11. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Analyze.cs +1 -1
  12. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Discover.cs +10 -23
  13. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Run.cs +9 -0
  14. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +15 -232
  15. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +1 -154
  16. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/ExperimentsManager.cs +3 -12
  17. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +5 -13
  18. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/PrivateSourceTimedOutException.cs +12 -0
  19. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/JobErrorBase.cs +4 -0
  20. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/ApiModel/PrivateSourceTimedOut.cs +10 -0
  21. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/AzurePackageDetailFinder.cs +30 -0
  22. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/DetailedPullRequestBodyGenerator.cs +237 -0
  23. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/GitHubPackageDetailFinder.cs +101 -0
  24. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/GitLabPackageDetailFinder.cs +107 -0
  25. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/HttpFetcher.cs +32 -0
  26. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/IHttpFetcher.cs +30 -0
  27. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/IPackageDetailFinder.cs +47 -0
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/IPullRequestBodyGenerator.cs +11 -0
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestBodyGenerator/SimplePullRequestBodyGenerator.cs +15 -0
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/PullRequestTextGenerator.cs +7 -3
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunWorker.cs +3 -525
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/CreateSecurityUpdatePullRequestHandler.cs +2 -2
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/GroupUpdateAllVersionsHandler.cs +4 -4
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandler.cs +2 -2
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandler.cs +2 -2
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandler.cs +2 -2
  37. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/FileWriters/FileWriterWorker.cs +85 -35
  38. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/FileWriters/XmlFileWriter.cs +27 -8
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackageReferenceUpdater.cs +1 -856
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateOperationBase.cs +18 -7
  41. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +16 -200
  42. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +21 -556
  43. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Analyze/AnalyzeWorkerTests.cs +9 -73
  44. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Clone/CloneWorkerTests.cs +2 -2
  45. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/DependencySolver/MSBuildDependencySolverTests.cs +1 -1
  46. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTestBase.cs +1 -20
  47. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.GlobalJson.cs +0 -2
  48. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.PackagesConfig.cs +3 -62
  49. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.Project.cs +13 -563
  50. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +20 -269
  51. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/SdkProjectDiscoveryTests.cs +2 -2
  52. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +0 -1
  53. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/EndToEndTests.cs +131 -131
  54. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/HttpApiHandlerTests.cs +1 -0
  55. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/JobErrorBaseTests.cs +7 -0
  56. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MessageReportTests.cs +11 -0
  57. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/MiscellaneousTests.cs +0 -203
  58. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestBodyGenerator/DetailedPullRequestBodyGeneratorTests.cs +871 -0
  59. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestBodyGenerator/IPackageDetailFinderTests.cs +28 -0
  60. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestBodyGenerator/TestHttpFetcher.cs +23 -0
  61. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestTextTests.cs +24 -24
  62. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/SerializationTests.cs +14 -12
  63. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/CreateSecurityUpdatePullRequestHandlerTests.cs +6 -6
  64. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/GroupUpdateAllVersionsHandlerTests.cs +18 -18
  65. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshGroupUpdatePullRequestHandlerTests.cs +15 -15
  66. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshSecurityUpdatePullRequestHandlerTests.cs +21 -21
  67. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/RefreshVersionUpdatePullRequestHandlerTests.cs +15 -15
  68. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdateHandlers/UpdateHandlersTestsBase.cs +1 -8
  69. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/FileWriterWorkerTests.cs +2 -2
  70. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/FileWriterWorkerTests_MiscellaneousTests.cs +45 -0
  71. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/FileWriters/XmlFileWriterTests.cs +111 -0
  72. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackageReferenceUpdaterTests.cs +1 -159
  73. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +26 -660
  74. data/helpers/lib/NuGetUpdater/global.json +1 -1
  75. metadata +18 -10
  76. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Run/RunResult.cs +0 -13
  77. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/PullRequestMessageTests.cs +0 -296
  78. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs +0 -3592
  79. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/UpdatePermittedAndMessageTests.cs +0 -457
  80. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DirsProj.cs +0 -378
  81. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterHelperTests.cs +0 -175
@@ -32,13 +32,36 @@ public class FileWriterWorker
32
32
  )
33
33
  {
34
34
  var updateOperations = new List<UpdateOperationBase>();
35
- var projectDirectory = Path.GetDirectoryName(projectPath.FullName)!;
36
- var projectDirectoryRelativeToRepoRoot = Path.GetRelativePath(repoContentsPath.FullName, projectDirectory).FullyNormalizedRootedPath();
35
+ var initialProjectDirectory = new DirectoryInfo(Path.GetDirectoryName(projectPath.FullName)!);
37
36
 
38
37
  // first try non-project updates
38
+ var nonProjectUpdates = await ProcessNonProjectUpdatesAsync(repoContentsPath, initialProjectDirectory, dependencyName, oldDependencyVersion, newDependencyVersion);
39
+ updateOperations.AddRange(nonProjectUpdates);
40
+
41
+ // then try packages.config updates
42
+ var packagesConfigUpdates = await ProcessPackagesConfigUpdatesAsync(repoContentsPath, projectPath, dependencyName, oldDependencyVersion, newDependencyVersion);
43
+ updateOperations.AddRange(packagesConfigUpdates);
44
+
45
+ // then try project updates
46
+ var packageReferenceUpdates = await ProcessPackageReferenceUpdatesAsync(repoContentsPath, initialProjectDirectory, projectPath, dependencyName, newDependencyVersion);
47
+ updateOperations.AddRange(packageReferenceUpdates);
48
+
49
+ var normalizedUpdateOperations = UpdateOperationBase.NormalizeUpdateOperationCollection(repoContentsPath.FullName, updateOperations);
50
+ return normalizedUpdateOperations;
51
+ }
52
+
53
+ private async Task<ImmutableArray<UpdateOperationBase>> ProcessNonProjectUpdatesAsync(
54
+ DirectoryInfo repoContentsPath,
55
+ DirectoryInfo initialProjectDirectory,
56
+ string dependencyName,
57
+ NuGetVersion oldDependencyVersion,
58
+ NuGetVersion newDependencyVersion
59
+ )
60
+ {
61
+ var updateOperations = new List<UpdateOperationBase>();
39
62
  var updatedDotNetToolsPath = await DotNetToolsJsonUpdater.UpdateDependencyAsync(
40
63
  repoContentsPath.FullName,
41
- projectDirectory,
64
+ initialProjectDirectory.FullName,
42
65
  dependencyName,
43
66
  oldDependencyVersion.ToString(),
44
67
  newDependencyVersion.ToString(),
@@ -57,7 +80,7 @@ public class FileWriterWorker
57
80
 
58
81
  var updatedGlobalJsonPath = await GlobalJsonUpdater.UpdateDependencyAsync(
59
82
  repoContentsPath.FullName,
60
- projectDirectory,
83
+ initialProjectDirectory.FullName,
61
84
  dependencyName,
62
85
  oldDependencyVersion.ToString(),
63
86
  newDependencyVersion.ToString(),
@@ -74,33 +97,54 @@ public class FileWriterWorker
74
97
  });
75
98
  }
76
99
 
77
- // then try packages.config updates
100
+ return [.. updateOperations];
101
+ }
102
+
103
+ private async Task<ImmutableArray<UpdateOperationBase>> ProcessPackagesConfigUpdatesAsync(
104
+ DirectoryInfo repoContentsPath,
105
+ FileInfo projectPath,
106
+ string dependencyName,
107
+ NuGetVersion oldDependencyVersion,
108
+ NuGetVersion newDependencyVersion
109
+ )
110
+ {
78
111
  var additionalFiles = ProjectHelper.GetAllAdditionalFilesFromProject(projectPath.FullName, ProjectHelper.PathFormat.Full);
79
112
  var packagesConfigFullPath = additionalFiles.Where(p => Path.GetFileName(p).Equals(ProjectHelper.PackagesConfigFileName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
80
- if (packagesConfigFullPath is not null)
113
+ if (packagesConfigFullPath is null)
81
114
  {
82
- var packagesConfigOperations = await PackagesConfigUpdater.UpdateDependencyAsync(
83
- repoContentsPath.FullName,
84
- projectPath.FullName,
85
- dependencyName,
86
- oldDependencyVersion.ToString(),
87
- newDependencyVersion.ToString(),
88
- packagesConfigFullPath,
89
- _logger
90
- );
91
- var packagesConfigOperationsWithNormalizedPaths = packagesConfigOperations
92
- .Select(op => op with { UpdatedFiles = [.. op.UpdatedFiles.Select(f => Path.GetRelativePath(repoContentsPath.FullName, f).FullyNormalizedRootedPath())] })
93
- .ToArray();
94
- updateOperations.AddRange(packagesConfigOperationsWithNormalizedPaths);
115
+ return [];
95
116
  }
96
117
 
97
- // then try project updates
98
- var initialDiscoveryResult = await _discoveryWorker.RunAsync(repoContentsPath.FullName, projectDirectoryRelativeToRepoRoot);
118
+ var packagesConfigOperations = await PackagesConfigUpdater.UpdateDependencyAsync(
119
+ repoContentsPath.FullName,
120
+ projectPath.FullName,
121
+ dependencyName,
122
+ oldDependencyVersion.ToString(),
123
+ newDependencyVersion.ToString(),
124
+ packagesConfigFullPath,
125
+ _logger
126
+ );
127
+ var packagesConfigOperationsWithNormalizedPaths = packagesConfigOperations
128
+ .Select(op => op with { UpdatedFiles = [.. op.UpdatedFiles.Select(f => Path.GetRelativePath(repoContentsPath.FullName, f).FullyNormalizedRootedPath())] })
129
+ .ToImmutableArray();
130
+ return packagesConfigOperationsWithNormalizedPaths;
131
+ }
132
+
133
+ private async Task<ImmutableArray<UpdateOperationBase>> ProcessPackageReferenceUpdatesAsync(
134
+ DirectoryInfo repoContentsPath,
135
+ DirectoryInfo initialProjectDirectory,
136
+ FileInfo projectPath,
137
+ string dependencyName,
138
+ NuGetVersion newDependencyVersion
139
+ )
140
+ {
141
+ var initialProjectDirectoryRelativeToRepoRoot = Path.GetRelativePath(repoContentsPath.FullName, initialProjectDirectory.FullName).FullyNormalizedRootedPath();
142
+ var initialDiscoveryResult = await _discoveryWorker.RunAsync(repoContentsPath.FullName, initialProjectDirectoryRelativeToRepoRoot);
99
143
  var initialProjectDiscovery = initialDiscoveryResult.GetProjectDiscoveryFromFullPath(repoContentsPath, projectPath);
100
144
  if (initialProjectDiscovery is null)
101
145
  {
102
146
  _logger.Info($"Unable to find project discovery for project {projectPath}.");
103
- return [.. updateOperations];
147
+ return [];
104
148
  }
105
149
 
106
150
  var initialRequestedDependency = initialProjectDiscovery.Dependencies
@@ -108,14 +152,14 @@ public class FileWriterWorker
108
152
  if (initialRequestedDependency is null || initialRequestedDependency.Version is null)
109
153
  {
110
154
  _logger.Info($"Dependency {dependencyName} not found in initial project discovery.");
111
- return [.. updateOperations];
155
+ return [];
112
156
  }
113
157
 
114
158
  var initialDependencyVersion = NuGetVersion.Parse(initialRequestedDependency.Version);
115
159
  if (initialDependencyVersion >= newDependencyVersion)
116
160
  {
117
161
  _logger.Info($"Dependency {dependencyName} is already at version {initialDependencyVersion}, no update needed.");
118
- return [.. updateOperations];
162
+ return [];
119
163
  }
120
164
 
121
165
  var initialTopLevelDependencies = initialProjectDiscovery.Dependencies
@@ -126,6 +170,7 @@ public class FileWriterWorker
126
170
  ? initialTopLevelDependencies.Select(d => d.Name.Equals(dependencyName, StringComparison.OrdinalIgnoreCase) ? newDependency : d).ToImmutableArray()
127
171
  : initialTopLevelDependencies.Concat([newDependency]).ToImmutableArray();
128
172
 
173
+ var updateOperations = new List<UpdateOperationBase>();
129
174
  foreach (var targetFramework in initialProjectDiscovery.TargetFrameworks)
130
175
  {
131
176
  var resolvedDependencies = await _dependencySolver.SolveAsync(initialTopLevelDependencies, desiredDependencies, targetFramework);
@@ -154,13 +199,13 @@ public class FileWriterWorker
154
199
  var orderedProjectDiscovery = GetProjectDiscoveryEvaluationOrder(repoContentsPath, initialDiscoveryResult, projectPath, _logger);
155
200
 
156
201
  // track original contents
157
- var originalFileContents = await GetOriginalFileContentsAsync(repoContentsPath, new DirectoryInfo(projectDirectory), orderedProjectDiscovery);
202
+ var originalFileContents = await GetOriginalFileContentsAsync(repoContentsPath, initialProjectDirectory, orderedProjectDiscovery);
158
203
 
159
204
  var allUpdatedFiles = new List<string>();
160
205
  foreach (var projectDiscovery in orderedProjectDiscovery)
161
206
  {
162
207
  var projectFullPath = Path.Join(repoContentsPath.FullName, initialDiscoveryResult.Path, projectDiscovery.FilePath).FullyNormalizedRootedPath();
163
- var updatedFiles = await TryPerformFileWritesAsync(repoContentsPath, new FileInfo(projectFullPath), projectDiscovery, resolvedDependencies.Value);
208
+ var updatedFiles = await TryPerformFileWritesAsync(_fileWriter, repoContentsPath, initialProjectDirectory, projectDiscovery, resolvedDependencies.Value);
164
209
  allUpdatedFiles.AddRange(updatedFiles);
165
210
  }
166
211
 
@@ -172,7 +217,7 @@ public class FileWriterWorker
172
217
  }
173
218
 
174
219
  // this final call to discover has the benefit of also updating the lock file if it exists
175
- var finalDiscoveryResult = await _discoveryWorker.RunAsync(repoContentsPath.FullName, projectDirectoryRelativeToRepoRoot);
220
+ var finalDiscoveryResult = await _discoveryWorker.RunAsync(repoContentsPath.FullName, initialProjectDirectoryRelativeToRepoRoot);
176
221
  var finalProjectDiscovery = finalDiscoveryResult.GetProjectDiscoveryFromFullPath(repoContentsPath, projectPath);
177
222
  if (finalProjectDiscovery is null)
178
223
  {
@@ -205,7 +250,7 @@ public class FileWriterWorker
205
250
  initialTopLevelDependencies,
206
251
  desiredDependencies,
207
252
  resolvedDependencies.Value,
208
- new ExperimentsManager() { UseDirectDiscovery = true },
253
+ new ExperimentsManager(),
209
254
  _logger);
210
255
  var filteredUpdateOperations = computedUpdateOperations
211
256
  .Where(op =>
@@ -222,8 +267,7 @@ public class FileWriterWorker
222
267
  updateOperations.AddRange(computedOperationsWithUpdatedFiles);
223
268
  }
224
269
 
225
- var normalizedUpdateOperations = UpdateOperationBase.NormalizeUpdateOperationCollection(repoContentsPath.FullName, updateOperations);
226
- return normalizedUpdateOperations;
270
+ return [.. updateOperations];
227
271
  }
228
272
 
229
273
  internal static async Task<Dictionary<string, string>> GetOriginalFileContentsAsync(DirectoryInfo repoContentsPath, DirectoryInfo initialStartingDirectory, IEnumerable<ProjectDiscoveryResult> projectDiscoveryResults)
@@ -292,16 +336,22 @@ public class FileWriterWorker
292
336
  return projectDiscoveryOrder;
293
337
  }
294
338
 
295
- private async Task<ImmutableArray<string>> TryPerformFileWritesAsync(DirectoryInfo repoContentsPath, FileInfo projectPath, ProjectDiscoveryResult projectDiscovery, ImmutableArray<Dependency> requiredPackageVersions)
339
+ internal static async Task<ImmutableArray<string>> TryPerformFileWritesAsync(
340
+ IFileWriter fileWriter,
341
+ DirectoryInfo repoContentsPath,
342
+ DirectoryInfo originalDiscoveryDirectory,
343
+ ProjectDiscoveryResult projectDiscovery,
344
+ ImmutableArray<Dependency> requiredPackageVersions
345
+ )
296
346
  {
297
- var originalFileContents = await GetOriginalFileContentsAsync(repoContentsPath, projectPath.Directory!, [projectDiscovery]);
347
+ var originalFileContents = await GetOriginalFileContentsAsync(repoContentsPath, originalDiscoveryDirectory, [projectDiscovery]);
298
348
  var relativeFilePaths = originalFileContents.Keys
299
349
  .Select(p => Path.GetRelativePath(repoContentsPath.FullName, p).FullyNormalizedRootedPath())
300
350
  .ToImmutableArray();
301
351
 
302
352
  // try update
303
353
  var addPackageReferenceElementForPinnedPackages = !projectDiscovery.CentralPackageTransitivePinningEnabled;
304
- var success = await _fileWriter.UpdatePackageVersionsAsync(repoContentsPath, [.. relativeFilePaths], projectDiscovery.Dependencies, requiredPackageVersions, addPackageReferenceElementForPinnedPackages);
354
+ var success = await fileWriter.UpdatePackageVersionsAsync(repoContentsPath, relativeFilePaths, projectDiscovery.Dependencies, requiredPackageVersions, addPackageReferenceElementForPinnedPackages);
305
355
  var updatedFiles = new List<string>();
306
356
  foreach (var (filePath, originalContents) in originalFileContents)
307
357
  {
@@ -320,7 +370,7 @@ public class FileWriterWorker
320
370
  await RestoreOriginalFileContentsAsync(originalFileContents);
321
371
  }
322
372
 
323
- var sortedUpdatedFiles = updatedFiles.OrderBy(p => p, StringComparer.Ordinal);
324
- return [.. sortedUpdatedFiles];
373
+ var sortedUpdatedFiles = updatedFiles.OrderBy(p => p, StringComparer.Ordinal).ToImmutableArray();
374
+ return sortedUpdatedFiles;
325
375
  }
326
376
  }
@@ -1,5 +1,6 @@
1
1
  using System.Collections.Immutable;
2
2
  using System.Text.RegularExpressions;
3
+ using System.Xml;
3
4
  using System.Xml.Linq;
4
5
 
5
6
  using NuGet.Versioning;
@@ -23,15 +24,20 @@ public class XmlFileWriter : IFileWriter
23
24
 
24
25
  private readonly ILogger _logger;
25
26
 
26
- // these file extensions are XML and can be updated; everything else is ignored
27
- private static readonly HashSet<string> SupportedFileExtensions =
28
- [
27
+ // these file extensions are valid project entrypoints; everything else is ignored
28
+ private static readonly HashSet<string> SupportedProjectFileExtensions = new(StringComparer.OrdinalIgnoreCase)
29
+ {
29
30
  ".csproj",
30
31
  ".vbproj",
31
32
  ".fsproj",
33
+ };
34
+
35
+ // these file extensions are valid additional files and can be updated; everything else is ignored
36
+ private static readonly HashSet<string> SupportedAdditionalFileExtensions = new(StringComparer.OrdinalIgnoreCase)
37
+ {
32
38
  ".props",
33
39
  ".targets",
34
- ];
40
+ };
35
41
 
36
42
  public XmlFileWriter(ILogger logger)
37
43
  {
@@ -54,8 +60,15 @@ public class XmlFileWriter : IFileWriter
54
60
 
55
61
  var updatesPerformed = requiredPackageVersions.ToDictionary(d => d.Name, _ => false, StringComparer.OrdinalIgnoreCase);
56
62
  var projectRelativePath = relativeFilePaths[0];
63
+ var projectExtension = Path.GetExtension(projectRelativePath);
64
+ if (!SupportedProjectFileExtensions.Contains(projectExtension))
65
+ {
66
+ _logger.Warn($"Project extension '{projectExtension}' not supported; skipping XML update.");
67
+ return false;
68
+ }
69
+
57
70
  var filesAndContentsTasks = relativeFilePaths
58
- .Where(path => SupportedFileExtensions.Contains(Path.GetExtension(path)))
71
+ .Where(path => SupportedProjectFileExtensions.Contains(Path.GetExtension(path)) || SupportedAdditionalFileExtensions.Contains(Path.GetExtension(path)))
59
72
  .Select(async path =>
60
73
  {
61
74
  var content = await ReadFileContentsAsync(repoContentsPath, path);
@@ -357,7 +370,7 @@ public class XmlFileWriter : IFileWriter
357
370
  {
358
371
  foreach (var (path, contents) in filesAndContents)
359
372
  {
360
- await WriteFileContentsAsync(repoContentsPath, path, contents.ToString());
373
+ await WriteFileContentsAsync(repoContentsPath, path, contents);
361
374
  }
362
375
  }
363
376
 
@@ -421,10 +434,16 @@ public class XmlFileWriter : IFileWriter
421
434
  return contents;
422
435
  }
423
436
 
424
- private static async Task WriteFileContentsAsync(DirectoryInfo repoContentsPath, string path, string contents)
437
+ private static async Task WriteFileContentsAsync(DirectoryInfo repoContentsPath, string path, XDocument document)
425
438
  {
426
439
  var fullPath = Path.Join(repoContentsPath.FullName, path);
427
- await File.WriteAllTextAsync(fullPath, contents);
440
+ var writerSettings = new XmlWriterSettings()
441
+ {
442
+ Async = true,
443
+ OmitXmlDeclaration = document.Declaration is null,
444
+ };
445
+ using var writer = XmlWriter.Create(fullPath, writerSettings);
446
+ await document.SaveAsync(writer, CancellationToken.None);
428
447
  }
429
448
 
430
449
  public static string CreateUpdatedVersionRangeString(VersionRange existingRange, NuGetVersion existingVersion, NuGetVersion requiredVersion)