dependabot-nuget 0.239.0 → 0.241.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/build +45 -0
  3. data/helpers/lib/NuGetUpdater/.editorconfig +364 -0
  4. data/helpers/lib/NuGetUpdater/.gitignore +5 -0
  5. data/helpers/lib/NuGetUpdater/Directory.Build.props +10 -0
  6. data/helpers/lib/NuGetUpdater/Directory.Common.props +16 -0
  7. data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Build.props +14 -0
  8. data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Build.targets +7 -0
  9. data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Packages.props +29 -0
  10. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Build.Tasks/NuGet.Build.Tasks.csproj +27 -0
  11. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/AssemblyMetadataExtractor.cs +203 -0
  12. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/NuGet.CommandLine.csproj +33 -0
  13. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Commands/NuGet.Commands.csproj +26 -0
  14. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Common/NuGet.Common.csproj +21 -0
  15. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Config +6 -0
  16. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Configuration/NuGet.Configuration.csproj +24 -0
  17. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Credentials/NuGet.Credentials.csproj +20 -0
  18. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.DependencyResolver.Core/NuGet.DependencyResolver.Core.csproj +22 -0
  19. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Frameworks/NuGet.Frameworks.csproj +17 -0
  20. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.LibraryModel/NuGet.LibraryModel.csproj +17 -0
  21. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.PackageManagement/NuGet.PackageManagement.csproj +27 -0
  22. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Packaging/NuGet.Packaging.csproj +28 -0
  23. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.ProjectModel/NuGet.ProjectModel.csproj +20 -0
  24. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Protocol/NuGet.Protocol.csproj +21 -0
  25. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Resolver/NuGet.Resolver.csproj +20 -0
  26. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Versioning/NuGet.Versioning.csproj +17 -0
  27. data/helpers/lib/NuGetUpdater/NuGetProjects/README.md +1 -0
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/FrameworkCheckCommand.cs +35 -0
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +43 -0
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/NuGetUpdater.Cli.csproj +20 -0
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +31 -0
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.FrameworkCheck.cs +42 -0
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +323 -0
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/NuGetUpdater.Cli.Test.csproj +24 -0
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Dependency.cs +3 -0
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyType.cs +12 -0
  37. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/BuildFile.cs +97 -0
  38. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/DotNetToolsJsonBuildFile.cs +24 -0
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +25 -0
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +32 -0
  41. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/PackagesConfigBuildFile.cs +31 -0
  42. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/ProjectBuildFile.cs +94 -0
  43. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/XmlBuildFile.cs +14 -0
  44. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/CompatabilityChecker.cs +39 -0
  45. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/FrameworkCompatibilityService.cs +73 -0
  46. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/SupportedFrameworks.cs +146 -0
  47. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/NuGetUpdater.Core.csproj +27 -0
  48. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs +316 -0
  49. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectResolver.cs +87 -0
  50. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/ConfigurationFile.cs +3 -0
  51. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +66 -0
  52. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +48 -0
  53. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +172 -0
  54. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SdkPackageUpdater.cs +498 -0
  55. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateResult.cs +7 -0
  56. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +105 -0
  57. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/JsonHelper.cs +222 -0
  58. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/Logger.cs +24 -0
  59. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +443 -0
  60. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/NuGetHelper.cs +15 -0
  61. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +69 -0
  62. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProcessExtensions.cs +66 -0
  63. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/XmlExtensions.cs +124 -0
  64. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/DotNetToolsJsonBuildFileTests.cs +52 -0
  65. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +63 -0
  66. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/PackagesConfigBuildFileTests.cs +63 -0
  67. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/ProjectBuildFileTests.cs +154 -0
  68. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/CompatibilityCheckerFacts.cs +64 -0
  69. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/FrameworkCompatibilityServiceFacts.cs +122 -0
  70. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/SupportedFrameworkFacts.cs +68 -0
  71. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/NuGetUpdater.Core.Test.csproj +23 -0
  72. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TemporaryDirectory.cs +36 -0
  73. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestExtensions.cs +15 -0
  74. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +79 -0
  75. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorker.DirsProj.cs +201 -0
  76. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +147 -0
  77. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DotNetTools.cs +225 -0
  78. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +217 -0
  79. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Mixed.cs +94 -0
  80. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +938 -0
  81. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Sdk.cs +2177 -0
  82. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/JsonHelperTests.cs +239 -0
  83. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +394 -0
  84. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterHelperTests.cs +179 -0
  85. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterTests.cs +238 -0
  86. data/helpers/lib/NuGetUpdater/NuGetUpdater.sln +152 -0
  87. data/helpers/lib/NuGetUpdater/xunit.runner.json +4 -0
  88. data/lib/dependabot/nuget/cache_manager.rb +2 -0
  89. data/lib/dependabot/nuget/file_fetcher.rb +51 -40
  90. data/lib/dependabot/nuget/file_parser/packages_config_parser.rb +0 -6
  91. data/lib/dependabot/nuget/file_parser/project_file_parser.rb +7 -22
  92. data/lib/dependabot/nuget/file_parser.rb +1 -1
  93. data/lib/dependabot/nuget/file_updater.rb +6 -2
  94. data/lib/dependabot/nuget/metadata_finder.rb +4 -4
  95. data/lib/dependabot/nuget/native_helpers.rb +7 -4
  96. data/lib/dependabot/nuget/nuget_client.rb +99 -0
  97. data/lib/dependabot/nuget/nuget_config_credential_helpers.rb +71 -0
  98. data/lib/dependabot/nuget/requirement.rb +1 -1
  99. data/lib/dependabot/nuget/update_checker/compatibility_checker.rb +2 -2
  100. data/lib/dependabot/nuget/update_checker/dependency_finder.rb +2 -2
  101. data/lib/dependabot/nuget/update_checker/nupkg_fetcher.rb +1 -29
  102. data/lib/dependabot/nuget/update_checker/property_updater.rb +2 -2
  103. data/lib/dependabot/nuget/update_checker/repository_finder.rb +39 -8
  104. data/lib/dependabot/nuget/update_checker/requirements_updater.rb +2 -2
  105. data/lib/dependabot/nuget/update_checker/tfm_comparer.rb +2 -2
  106. data/lib/dependabot/nuget/update_checker/tfm_finder.rb +2 -2
  107. data/lib/dependabot/nuget/update_checker/version_finder.rb +4 -42
  108. metadata +107 -5
@@ -0,0 +1,2177 @@
1
+ using System.Threading.Tasks;
2
+
3
+ using Xunit;
4
+
5
+ namespace NuGetUpdater.Core.Test.Update;
6
+
7
+ public partial class UpdateWorkerTests
8
+ {
9
+ public class Sdk : UpdateWorkerTestBase
10
+ {
11
+ public Sdk()
12
+ {
13
+ MSBuildHelper.RegisterMSBuild();
14
+ }
15
+
16
+ [Theory]
17
+ [InlineData("net472")]
18
+ [InlineData("netstandard2.0")]
19
+ [InlineData("net5.0")]
20
+ [InlineData("net6.0")]
21
+ [InlineData("net7.0")]
22
+ [InlineData("net8.0")]
23
+ public async Task UpdateVersionAttribute_InProjectFile_ForPackageReferenceInclude(string tfm)
24
+ {
25
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
26
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
27
+ // initial
28
+ projectContents: $"""
29
+ <Project Sdk="Microsoft.NET.Sdk">
30
+ <PropertyGroup>
31
+ <TargetFramework>{tfm}</TargetFramework>
32
+ </PropertyGroup>
33
+
34
+ <ItemGroup>
35
+ <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
36
+ </ItemGroup>
37
+ </Project>
38
+ """,
39
+ // expected
40
+ expectedProjectContents: $"""
41
+ <Project Sdk="Microsoft.NET.Sdk">
42
+ <PropertyGroup>
43
+ <TargetFramework>{tfm}</TargetFramework>
44
+ </PropertyGroup>
45
+
46
+ <ItemGroup>
47
+ <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
48
+ </ItemGroup>
49
+ </Project>
50
+ """);
51
+ }
52
+
53
+
54
+ [Theory]
55
+ [InlineData("$(NewtonsoftJsonVersion")]
56
+ [InlineData("$NewtonsoftJsonVersion)")]
57
+ [InlineData("$NewtonsoftJsonVersion")]
58
+ [InlineData("NewtonsoftJsonVersion)")]
59
+ public async Task Update_InvalidFile_DoesNotThrow(string versionString)
60
+ {
61
+ await TestNoChangeforProject("Newtonsoft.Json", "9.0.1", "13.0.1",
62
+ $"""
63
+ <Project Sdk="Microsoft.NET.Sdk">">
64
+ <PropertyGroup>
65
+ <TargetFramework>netstandard2.0</TargetFramework>
66
+ <NewtonsoftJsonVersion>9.0.1</NewtonsoftJsonVersion>
67
+ </PropertyGroup>
68
+ <ItemGroup>
69
+ <PackageReference Include="Newtonsoft.Json" Version="{versionString}" />
70
+ </ItemGroup>
71
+ </Project>
72
+ """);
73
+ }
74
+
75
+ [Fact]
76
+ public async Task UpdateFindsNearestNugetConfig_AndSucceeds()
77
+ {
78
+ // Clean the cache to ensure we don't find a cached version of packages.
79
+ await ProcessEx.RunAsync("dotnet", $"nuget locals -c all");
80
+ // If the Top-Level NugetConfig was found we would have failed.
81
+ var privateNugetContent = $"""
82
+ <?xml version="1.0" encoding="utf-8"?>
83
+ <configuration>
84
+
85
+ <packageSources>
86
+ <clear />
87
+ <add key="nuget_PrivateFeed" value="https://api.nuget.org/v3/index.json" />
88
+ </packageSources>
89
+ </configuration>
90
+ """;
91
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
92
+ projectFile: (Path: "Directory/Project.csproj", Content: """
93
+ <Project Sdk="Microsoft.NET.Sdk">
94
+ <PropertyGroup>
95
+ <TargetFramework>netstandard2.0</TargetFramework>
96
+ </PropertyGroup>
97
+ <ItemGroup>
98
+ <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
99
+ </ItemGroup>
100
+ </Project>
101
+ """),
102
+ $"""
103
+ <Project Sdk="Microsoft.NET.Sdk">
104
+ <PropertyGroup>
105
+ <TargetFramework>netstandard2.0</TargetFramework>
106
+ </PropertyGroup>
107
+ <ItemGroup>
108
+ <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
109
+ </ItemGroup>
110
+ </Project>
111
+ """,
112
+ additionalFiles: new (string Path, string Content)[] {
113
+ (Path: "NuGet.config", Content: $"""
114
+ <?xml version="1.0" encoding="utf-8"?>
115
+ <configuration>
116
+ <packageSources>
117
+ <clear />
118
+ <add key="nuget_PublicFeed" value="https://api.nuget.org/v3/BROKEN.json" />
119
+ </packageSources>
120
+ </configuration>
121
+ """),
122
+ (Path: "Directory/NuGet.config", Content: privateNugetContent)
123
+ });
124
+ }
125
+
126
+ [Fact]
127
+ public async Task UpdateReturnsEmptyArray_WhenBuildFails()
128
+ {
129
+ // Clean the cache to ensure we don't find a cached version of packages.
130
+ await ProcessEx.RunAsync("dotnet", $"nuget locals -c all");
131
+ await TestNoChangeforProject("Newtonsoft.Json", "9.0.1", "13.0.1",
132
+ """
133
+ <Project Sdk="Microsoft.NET.Sdk">
134
+ <PropertyGroup>
135
+ <TargetFramework>netstandard2.0</TargetFramework>
136
+ </PropertyGroup>
137
+ <ItemGroup>
138
+ <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
139
+ </ItemGroup>
140
+ </Project>
141
+ """,
142
+ additionalFiles: new (string Path, string Content)[] {
143
+ (Path: "NuGet.config", Content: $"""
144
+ <?xml version="1.0" encoding="utf-8"?>
145
+ <configuration>
146
+ <config>
147
+ <add key="repositoryPath" value="./packages" />
148
+ </config>
149
+ <packageSources>
150
+ <clear />
151
+ <add key="nuget_BrokenFeed" value="https://api.nuget.org/BrokenFeed" />
152
+ </packageSources>
153
+ </configuration>
154
+ """),
155
+ });
156
+ }
157
+
158
+ [Fact]
159
+ public async Task UpdateExactMatchVersionAttribute_InProjectFile_ForPackageReferenceInclude()
160
+ {
161
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
162
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
163
+ // initial
164
+ projectContents: $"""
165
+ <Project Sdk="Microsoft.NET.Sdk">
166
+ <PropertyGroup>
167
+ <TargetFramework>net6.0</TargetFramework>
168
+ </PropertyGroup>
169
+
170
+ <ItemGroup>
171
+ <PackageReference Include="Newtonsoft.Json" Version="[9.0.1]" />
172
+ </ItemGroup>
173
+ </Project>
174
+ """,
175
+ // expected
176
+ expectedProjectContents: $"""
177
+ <Project Sdk="Microsoft.NET.Sdk">
178
+ <PropertyGroup>
179
+ <TargetFramework>net6.0</TargetFramework>
180
+ </PropertyGroup>
181
+
182
+ <ItemGroup>
183
+ <PackageReference Include="Newtonsoft.Json" Version="[13.0.1]" />
184
+ </ItemGroup>
185
+ </Project>
186
+ """);
187
+ }
188
+
189
+ [Fact]
190
+ public async Task AddPackageReference_InProjectFile_ForTransientDependency()
191
+ {
192
+ // add transient System.Text.Json from 5.0.1 to 5.0.2
193
+ await TestUpdateForProject("System.Text.Json", "5.0.1", "5.0.2", isTransitive: true,
194
+ // initial
195
+ projectContents: """
196
+ <Project Sdk="Microsoft.NET.Sdk">
197
+
198
+ <PropertyGroup>
199
+ <TargetFramework>netcoreapp3.1</TargetFramework>
200
+ </PropertyGroup>
201
+
202
+ <ItemGroup>
203
+ <PackageReference Include="Mongo2Go" Version="3.1.3" />
204
+ </ItemGroup>
205
+
206
+ </Project>
207
+ """,
208
+ // expected
209
+ expectedProjectContents: """
210
+ <Project Sdk="Microsoft.NET.Sdk">
211
+
212
+ <PropertyGroup>
213
+ <TargetFramework>netcoreapp3.1</TargetFramework>
214
+ </PropertyGroup>
215
+
216
+ <ItemGroup>
217
+ <PackageReference Include="Mongo2Go" Version="3.1.3" />
218
+ <PackageReference Include="System.Text.Json" Version="5.0.2" />
219
+ </ItemGroup>
220
+
221
+ </Project>
222
+ """);
223
+ }
224
+
225
+ [Fact]
226
+ public async Task UpdateVersionAttribute_InProjectFile_ForAnalyzerPackageReferenceInclude()
227
+ {
228
+ // update Microsoft.CodeAnalysis.Analyzers from 3.3.0 to 3.3.4
229
+ await TestUpdateForProject("Microsoft.CodeAnalysis.Analyzers", "3.3.0", "3.3.4",
230
+ // initial
231
+ projectContents: """
232
+ <Project Sdk="Microsoft.NET.Sdk">
233
+ <PropertyGroup>
234
+ <TargetFramework>netstandard2.0</TargetFramework>
235
+ </PropertyGroup>
236
+
237
+ <ItemGroup>
238
+ <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.0">
239
+ <PrivateAssets>all</PrivateAssets>
240
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
241
+ </PackageReference>
242
+ </ItemGroup>
243
+ </Project>
244
+ """,
245
+ // expected
246
+ expectedProjectContents: """
247
+ <Project Sdk="Microsoft.NET.Sdk">
248
+ <PropertyGroup>
249
+ <TargetFramework>netstandard2.0</TargetFramework>
250
+ </PropertyGroup>
251
+
252
+ <ItemGroup>
253
+ <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
254
+ <PrivateAssets>all</PrivateAssets>
255
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
256
+ </PackageReference>
257
+ </ItemGroup>
258
+ </Project>
259
+ """);
260
+ }
261
+
262
+ [Fact]
263
+ public async Task UpdateVersionAttribute_InProjectFile_ForMultiplePackageReferences()
264
+ {
265
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
266
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
267
+ // initial
268
+ projectContents: """
269
+ <Project Sdk="Microsoft.NET.Sdk">
270
+ <PropertyGroup>
271
+ <TargetFramework>netstandard2.0</TargetFramework>
272
+ </PropertyGroup>
273
+
274
+ <ItemGroup>
275
+ <PackageReference Include="Newtonsoft.JSON" Version="9.0.1" />
276
+ <PackageReference Update="Newtonsoft.Json" Version="9.0.1" />
277
+ </ItemGroup>
278
+ </Project>
279
+ """,
280
+ // expected
281
+ expectedProjectContents: """
282
+ <Project Sdk="Microsoft.NET.Sdk">
283
+ <PropertyGroup>
284
+ <TargetFramework>netstandard2.0</TargetFramework>
285
+ </PropertyGroup>
286
+
287
+ <ItemGroup>
288
+ <PackageReference Include="Newtonsoft.JSON" Version="13.0.1" />
289
+ <PackageReference Update="Newtonsoft.Json" Version="13.0.1" />
290
+ </ItemGroup>
291
+ </Project>
292
+ """);
293
+ }
294
+
295
+ [Fact]
296
+ public async Task UpdateVersionAttribute_InProjectFile_ForPackageReferenceUpdate()
297
+ {
298
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
299
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
300
+ // initial
301
+ projectContents: """
302
+ <Project Sdk="Microsoft.NET.Sdk">
303
+ <PropertyGroup>
304
+ <TargetFramework>netstandard2.0</TargetFramework>
305
+ </PropertyGroup>
306
+
307
+ <ItemGroup>
308
+ <PackageReference Include="Newtonsoft.Json" />
309
+ <PackageReference Update="Newtonsoft.Json" Version="9.0.1" />
310
+ </ItemGroup>
311
+ </Project>
312
+ """,
313
+ // expected
314
+ expectedProjectContents: """
315
+ <Project Sdk="Microsoft.NET.Sdk">
316
+ <PropertyGroup>
317
+ <TargetFramework>netstandard2.0</TargetFramework>
318
+ </PropertyGroup>
319
+
320
+ <ItemGroup>
321
+ <PackageReference Include="Newtonsoft.Json" />
322
+ <PackageReference Update="Newtonsoft.Json" Version="13.0.1" />
323
+ </ItemGroup>
324
+ </Project>
325
+ """);
326
+ }
327
+
328
+ [Fact]
329
+ public async Task UpdateVersionAttribute_InDirectoryPackages_ForPackageVersion()
330
+ {
331
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
332
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
333
+ // initial
334
+ projectContents: """
335
+ <Project Sdk="Microsoft.NET.Sdk">
336
+ <PropertyGroup>
337
+ <TargetFramework>netstandard2.0</TargetFramework>
338
+ </PropertyGroup>
339
+
340
+ <ItemGroup>
341
+ <PackageReference Include="Newtonsoft.Json" />
342
+ </ItemGroup>
343
+ </Project>
344
+ """,
345
+ additionalFiles: new[]
346
+ {
347
+ ("Directory.Packages.props", """
348
+ <Project>
349
+ <PropertyGroup>
350
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
351
+ </PropertyGroup>
352
+
353
+ <ItemGroup>
354
+ <PackageVersion Include="Newtonsoft.Json" Version="9.0.1" />
355
+ </ItemGroup>
356
+ </Project>
357
+ """)
358
+ },
359
+ // expected
360
+ expectedProjectContents: """
361
+ <Project Sdk="Microsoft.NET.Sdk">
362
+ <PropertyGroup>
363
+ <TargetFramework>netstandard2.0</TargetFramework>
364
+ </PropertyGroup>
365
+
366
+ <ItemGroup>
367
+ <PackageReference Include="Newtonsoft.Json" />
368
+ </ItemGroup>
369
+ </Project>
370
+ """,
371
+ additionalFilesExpected: new[]
372
+ {
373
+ ("Directory.Packages.props", """
374
+ <Project>
375
+ <PropertyGroup>
376
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
377
+ </PropertyGroup>
378
+
379
+ <ItemGroup>
380
+ <PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
381
+ </ItemGroup>
382
+ </Project>
383
+ """)
384
+ });
385
+ }
386
+
387
+ [Fact]
388
+ public async Task UpdateExactMatchVersionAttribute_InDirectoryPackages_ForPackageVersion()
389
+ {
390
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
391
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
392
+ // initial
393
+ projectContents: """
394
+ <Project Sdk="Microsoft.NET.Sdk">
395
+ <PropertyGroup>
396
+ <TargetFramework>netstandard2.0</TargetFramework>
397
+ </PropertyGroup>
398
+
399
+ <ItemGroup>
400
+ <PackageReference Include="Newtonsoft.Json" />
401
+ </ItemGroup>
402
+ </Project>
403
+ """,
404
+ additionalFiles: new[]
405
+ {
406
+ ("Directory.Packages.props", """
407
+ <Project>
408
+ <PropertyGroup>
409
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
410
+ </PropertyGroup>
411
+
412
+ <ItemGroup>
413
+ <PackageVersion Include="Newtonsoft.Json" Version="[9.0.1]" />
414
+ </ItemGroup>
415
+ </Project>
416
+ """)
417
+ },
418
+ // expected
419
+ expectedProjectContents: """
420
+ <Project Sdk="Microsoft.NET.Sdk">
421
+ <PropertyGroup>
422
+ <TargetFramework>netstandard2.0</TargetFramework>
423
+ </PropertyGroup>
424
+
425
+ <ItemGroup>
426
+ <PackageReference Include="Newtonsoft.Json" />
427
+ </ItemGroup>
428
+ </Project>
429
+ """,
430
+ additionalFilesExpected: new[]
431
+ {
432
+ ("Directory.Packages.props", """
433
+ <Project>
434
+ <PropertyGroup>
435
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
436
+ </PropertyGroup>
437
+
438
+ <ItemGroup>
439
+ <PackageVersion Include="Newtonsoft.Json" Version="[13.0.1]" />
440
+ </ItemGroup>
441
+ </Project>
442
+ """)
443
+ });
444
+ }
445
+
446
+ [Fact]
447
+ public async Task UpdatePropertyValue_InProjectFile_ForPackageReferenceIncludeWithExactVersion()
448
+ {
449
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
450
+ // initial
451
+ projectContents: """
452
+ <Project Sdk="Microsoft.NET.Sdk">
453
+ <PropertyGroup>
454
+ <TargetFramework>netstandard2.0</TargetFramework>
455
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
456
+ </PropertyGroup>
457
+
458
+ <ItemGroup>
459
+ <PackageReference Include="Newtonsoft.Json" Version="[$(NewtonsoftJsonPackageVersion)]" />
460
+ </ItemGroup>
461
+ </Project>
462
+ """,
463
+ // expected
464
+ expectedProjectContents: """
465
+ <Project Sdk="Microsoft.NET.Sdk">
466
+ <PropertyGroup>
467
+ <TargetFramework>netstandard2.0</TargetFramework>
468
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
469
+ </PropertyGroup>
470
+
471
+ <ItemGroup>
472
+ <PackageReference Include="Newtonsoft.Json" Version="[$(NewtonsoftJsonPackageVersion)]" />
473
+ </ItemGroup>
474
+ </Project>
475
+ """);
476
+ }
477
+
478
+ [Fact]
479
+ public async Task UpdateDifferentCasedPropertyValue_InProjectFile_ForPackageReferenceInclude()
480
+ {
481
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
482
+ // initial
483
+ projectContents: """
484
+ <Project Sdk="Microsoft.NET.Sdk">
485
+ <PropertyGroup>
486
+ <TargetFramework>netstandard2.0</TargetFramework>
487
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
488
+ </PropertyGroup>
489
+
490
+ <ItemGroup>
491
+ <PackageReference Include="Newtonsoft.Json" Version="$(newtonsoftjsonpackageversion)" />
492
+ </ItemGroup>
493
+ </Project>
494
+ """,
495
+ // expected
496
+ expectedProjectContents: """
497
+ <Project Sdk="Microsoft.NET.Sdk">
498
+ <PropertyGroup>
499
+ <TargetFramework>netstandard2.0</TargetFramework>
500
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
501
+ </PropertyGroup>
502
+
503
+ <ItemGroup>
504
+ <PackageReference Include="Newtonsoft.Json" Version="$(newtonsoftjsonpackageversion)" />
505
+ </ItemGroup>
506
+ </Project>
507
+ """);
508
+ }
509
+
510
+ [Fact]
511
+ public async Task UpdatePropertyValue_InProjectFile_ForPackageReferenceInclude()
512
+ {
513
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
514
+ // initial
515
+ projectContents: """
516
+ <Project Sdk="Microsoft.NET.Sdk">
517
+ <PropertyGroup>
518
+ <TargetFramework>netstandard2.0</TargetFramework>
519
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
520
+ </PropertyGroup>
521
+
522
+ <ItemGroup>
523
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
524
+ </ItemGroup>
525
+ </Project>
526
+ """,
527
+ // expected
528
+ expectedProjectContents: """
529
+ <Project Sdk="Microsoft.NET.Sdk">
530
+ <PropertyGroup>
531
+ <TargetFramework>netstandard2.0</TargetFramework>
532
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
533
+ </PropertyGroup>
534
+
535
+ <ItemGroup>
536
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
537
+ </ItemGroup>
538
+ </Project>
539
+ """);
540
+ }
541
+
542
+ [Fact]
543
+ public async Task UpdateExactMatchPropertyValue_InProjectFile_ForPackageReferenceInclude()
544
+ {
545
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
546
+ // initial
547
+ projectContents: """
548
+ <Project Sdk="Microsoft.NET.Sdk">
549
+ <PropertyGroup>
550
+ <TargetFramework>netstandard2.0</TargetFramework>
551
+ <NewtonsoftJsonPackageVersion>[9.0.1]</NewtonsoftJsonPackageVersion>
552
+ </PropertyGroup>
553
+
554
+ <ItemGroup>
555
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
556
+ </ItemGroup>
557
+ </Project>
558
+ """,
559
+ // expected
560
+ expectedProjectContents: """
561
+ <Project Sdk="Microsoft.NET.Sdk">
562
+ <PropertyGroup>
563
+ <TargetFramework>netstandard2.0</TargetFramework>
564
+ <NewtonsoftJsonPackageVersion>[13.0.1]</NewtonsoftJsonPackageVersion>
565
+ </PropertyGroup>
566
+
567
+ <ItemGroup>
568
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
569
+ </ItemGroup>
570
+ </Project>
571
+ """);
572
+ }
573
+
574
+ [Fact]
575
+ public async Task UpdateVersionAttributeAndPropertyValue_InProjectFile_ForMultiplePackageReferences()
576
+ {
577
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
578
+ // initial
579
+ projectContents: """
580
+ <Project Sdk="Microsoft.NET.Sdk">
581
+ <PropertyGroup>
582
+ <TargetFramework>netstandard2.0</TargetFramework>
583
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
584
+ </PropertyGroup>
585
+
586
+ <ItemGroup>
587
+ <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
588
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
589
+ </ItemGroup>
590
+ </Project>
591
+ """,
592
+ // expected
593
+ expectedProjectContents: """
594
+ <Project Sdk="Microsoft.NET.Sdk">
595
+ <PropertyGroup>
596
+ <TargetFramework>netstandard2.0</TargetFramework>
597
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
598
+ </PropertyGroup>
599
+
600
+ <ItemGroup>
601
+ <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
602
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
603
+ </ItemGroup>
604
+ </Project>
605
+ """);
606
+ }
607
+
608
+ [Fact]
609
+ public async Task UpdatePropertyValue_InProjectFile_ForPackageReferenceUpdate()
610
+ {
611
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
612
+ // initial
613
+ projectContents: """
614
+ <Project Sdk="Microsoft.NET.Sdk">
615
+ <PropertyGroup>
616
+ <TargetFramework>netstandard2.0</TargetFramework>
617
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
618
+ </PropertyGroup>
619
+
620
+ <ItemGroup>
621
+ <PackageReference Include="Newtonsoft.Json" />
622
+ <PackageReference Update="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
623
+ </ItemGroup>
624
+ </Project>
625
+ """,
626
+ // expected
627
+ expectedProjectContents: """
628
+ <Project Sdk="Microsoft.NET.Sdk">
629
+ <PropertyGroup>
630
+ <TargetFramework>netstandard2.0</TargetFramework>
631
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
632
+ </PropertyGroup>
633
+
634
+ <ItemGroup>
635
+ <PackageReference Include="Newtonsoft.Json" />
636
+ <PackageReference Update="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
637
+ </ItemGroup>
638
+ </Project>
639
+ """);
640
+ }
641
+
642
+ [Fact]
643
+ public async Task UpdatePropertyValue_InDirectoryProps_ForPackageVersion()
644
+ {
645
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
646
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
647
+ // initial
648
+ projectContents: """
649
+ <Project Sdk="Microsoft.NET.Sdk">
650
+ <PropertyGroup>
651
+ <TargetFramework>netstandard2.0</TargetFramework>
652
+ </PropertyGroup>
653
+
654
+ <ItemGroup>
655
+ <PackageReference Include="Newtonsoft.Json" />
656
+ </ItemGroup>
657
+ </Project>
658
+ """,
659
+ additionalFiles: new[]
660
+ {
661
+ ("Directory.Packages.props", """
662
+ <Project>
663
+ <PropertyGroup>
664
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
665
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
666
+ </PropertyGroup>
667
+
668
+ <ItemGroup>
669
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
670
+ </ItemGroup>
671
+ </Project>
672
+ """)
673
+ },
674
+ // expected
675
+ expectedProjectContents: """
676
+ <Project Sdk="Microsoft.NET.Sdk">
677
+ <PropertyGroup>
678
+ <TargetFramework>netstandard2.0</TargetFramework>
679
+ </PropertyGroup>
680
+
681
+ <ItemGroup>
682
+ <PackageReference Include="Newtonsoft.Json" />
683
+ </ItemGroup>
684
+ </Project>
685
+ """,
686
+ additionalFilesExpected: new[]
687
+ {
688
+ ("Directory.Packages.props", """
689
+ <Project>
690
+ <PropertyGroup>
691
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
692
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
693
+ </PropertyGroup>
694
+
695
+ <ItemGroup>
696
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
697
+ </ItemGroup>
698
+ </Project>
699
+ """)
700
+ });
701
+ }
702
+
703
+ [Fact]
704
+ public async Task UpdateExactMatchPropertyValue_InDirectoryProps_ForPackageVersion()
705
+ {
706
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
707
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
708
+ // initial
709
+ projectContents: """
710
+ <Project Sdk="Microsoft.NET.Sdk">
711
+ <PropertyGroup>
712
+ <TargetFramework>netstandard2.0</TargetFramework>
713
+ </PropertyGroup>
714
+
715
+ <ItemGroup>
716
+ <PackageReference Include="Newtonsoft.Json" />
717
+ </ItemGroup>
718
+ </Project>
719
+ """,
720
+ additionalFiles: new[]
721
+ {
722
+ ("Directory.Packages.props", """
723
+ <Project>
724
+ <PropertyGroup>
725
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
726
+ <NewtonsoftJsonPackageVersion>[9.0.1]</NewtonsoftJsonPackageVersion>
727
+ </PropertyGroup>
728
+
729
+ <ItemGroup>
730
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
731
+ </ItemGroup>
732
+ </Project>
733
+ """)
734
+ },
735
+ // expected
736
+ expectedProjectContents: """
737
+ <Project Sdk="Microsoft.NET.Sdk">
738
+ <PropertyGroup>
739
+ <TargetFramework>netstandard2.0</TargetFramework>
740
+ </PropertyGroup>
741
+
742
+ <ItemGroup>
743
+ <PackageReference Include="Newtonsoft.Json" />
744
+ </ItemGroup>
745
+ </Project>
746
+ """,
747
+ additionalFilesExpected: new[]
748
+ {
749
+ ("Directory.Packages.props", """
750
+ <Project>
751
+ <PropertyGroup>
752
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
753
+ <NewtonsoftJsonPackageVersion>[13.0.1]</NewtonsoftJsonPackageVersion>
754
+ </PropertyGroup>
755
+
756
+ <ItemGroup>
757
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
758
+ </ItemGroup>
759
+ </Project>
760
+ """)
761
+ });
762
+ }
763
+
764
+ [Fact]
765
+ public async Task UpdateVersionOverrideAttributeAndPropertyValue_InProjectFileAndDirectoryProps_ForPackageVersion()
766
+ {
767
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
768
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
769
+ // initial
770
+ projectContents: """
771
+ <Project Sdk="Microsoft.NET.Sdk">
772
+ <PropertyGroup>
773
+ <TargetFramework>netstandard2.0</TargetFramework>
774
+ </PropertyGroup>
775
+
776
+ <ItemGroup>
777
+ <PackageReference Include="Newtonsoft.Json" VersionOverride="9.0.1" />
778
+ </ItemGroup>
779
+ </Project>
780
+ """,
781
+ additionalFiles: new[]
782
+ {
783
+ ("Directory.Packages.props", """
784
+ <Project>
785
+ <PropertyGroup>
786
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
787
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
788
+ </PropertyGroup>
789
+
790
+ <ItemGroup>
791
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
792
+ </ItemGroup>
793
+ </Project>
794
+ """)
795
+ },
796
+ // expected
797
+ expectedProjectContents: """
798
+ <Project Sdk="Microsoft.NET.Sdk">
799
+ <PropertyGroup>
800
+ <TargetFramework>netstandard2.0</TargetFramework>
801
+ </PropertyGroup>
802
+
803
+ <ItemGroup>
804
+ <PackageReference Include="Newtonsoft.Json" VersionOverride="13.0.1" />
805
+ </ItemGroup>
806
+ </Project>
807
+ """,
808
+ additionalFilesExpected: new[]
809
+ {
810
+ ("Directory.Packages.props", """
811
+ <Project>
812
+ <PropertyGroup>
813
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
814
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
815
+ </PropertyGroup>
816
+
817
+ <ItemGroup>
818
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
819
+ </ItemGroup>
820
+ </Project>
821
+ """)
822
+ });
823
+ }
824
+
825
+ [Fact]
826
+ public async Task UpdateVersionAttribute_InDirectoryProps_ForGlobalPackageReference()
827
+ {
828
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
829
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
830
+ // initial
831
+ projectContents: """
832
+ <Project Sdk="Microsoft.NET.Sdk">
833
+ <PropertyGroup>
834
+ <TargetFramework>netstandard2.0</TargetFramework>
835
+ </PropertyGroup>
836
+ </Project>
837
+ """,
838
+ additionalFiles: new[]
839
+ {
840
+ ("Directory.Packages.props", """
841
+ <Project>
842
+ <PropertyGroup>
843
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
844
+ </PropertyGroup>
845
+
846
+ <ItemGroup>
847
+ <GlobalPackageReference Include="Newtonsoft.Json" Version="9.0.1" />
848
+ </ItemGroup>
849
+ </Project>
850
+ """)
851
+ },
852
+ // expected
853
+ expectedProjectContents: """
854
+ <Project Sdk="Microsoft.NET.Sdk">
855
+ <PropertyGroup>
856
+ <TargetFramework>netstandard2.0</TargetFramework>
857
+ </PropertyGroup>
858
+ </Project>
859
+ """,
860
+ additionalFilesExpected: new[]
861
+ {
862
+ ("Directory.Packages.props", """
863
+ <Project>
864
+ <PropertyGroup>
865
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
866
+ </PropertyGroup>
867
+
868
+ <ItemGroup>
869
+ <GlobalPackageReference Include="Newtonsoft.Json" Version="13.0.1" />
870
+ </ItemGroup>
871
+ </Project>
872
+ """)
873
+ });
874
+ }
875
+
876
+ [Fact]
877
+ public async Task UpdatePropertyValue_InDirectoryProps_ForGlobalPackageReference()
878
+ {
879
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
880
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
881
+ // initial
882
+ projectContents: """
883
+ <Project Sdk="Microsoft.NET.Sdk">
884
+ <PropertyGroup>
885
+ <TargetFramework>netstandard2.0</TargetFramework>
886
+ </PropertyGroup>
887
+ </Project>
888
+ """,
889
+ additionalFiles: new[]
890
+ {
891
+ ("Directory.Packages.props", """
892
+ <Project>
893
+ <PropertyGroup>
894
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
895
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
896
+ </PropertyGroup>
897
+
898
+ <ItemGroup>
899
+ <GlobalPackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
900
+ </ItemGroup>
901
+ </Project>
902
+ """)
903
+ },
904
+ // expected
905
+ expectedProjectContents: """
906
+ <Project Sdk="Microsoft.NET.Sdk">
907
+ <PropertyGroup>
908
+ <TargetFramework>netstandard2.0</TargetFramework>
909
+ </PropertyGroup>
910
+ </Project>
911
+ """,
912
+ additionalFilesExpected: new[]
913
+ {
914
+ ("Directory.Packages.props", """
915
+ <Project>
916
+ <PropertyGroup>
917
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
918
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
919
+ </PropertyGroup>
920
+
921
+ <ItemGroup>
922
+ <GlobalPackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
923
+ </ItemGroup>
924
+ </Project>
925
+ """)
926
+ });
927
+ }
928
+
929
+ [Fact]
930
+ public async Task UpdatePropertyValue_InDirectoryProps_ForPackageReferenceInclude()
931
+ {
932
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
933
+ // initial project
934
+ projectContents: """
935
+ <Project Sdk="Microsoft.NET.Sdk">
936
+ <PropertyGroup>
937
+ <TargetFramework>netstandard2.0</TargetFramework>
938
+ </PropertyGroup>
939
+
940
+ <ItemGroup>
941
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
942
+ </ItemGroup>
943
+ </Project>
944
+ """,
945
+ additionalFiles: new[]
946
+ {
947
+ // initial props file
948
+ ("Directory.Build.props", """
949
+ <Project>
950
+ <PropertyGroup>
951
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
952
+ </PropertyGroup>
953
+ </Project>
954
+ """)
955
+ },
956
+ // expected project
957
+ expectedProjectContents: """
958
+ <Project Sdk="Microsoft.NET.Sdk">
959
+ <PropertyGroup>
960
+ <TargetFramework>netstandard2.0</TargetFramework>
961
+ </PropertyGroup>
962
+
963
+ <ItemGroup>
964
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
965
+ </ItemGroup>
966
+ </Project>
967
+ """,
968
+ additionalFilesExpected: new[]
969
+ {
970
+ // expected props file
971
+ ("Directory.Build.props", """
972
+ <Project>
973
+ <PropertyGroup>
974
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
975
+ </PropertyGroup>
976
+ </Project>
977
+ """)
978
+ });
979
+ }
980
+
981
+ [Fact]
982
+ public async Task UpdatePropertyValue_InProps_ForPackageReferenceInclude()
983
+ {
984
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
985
+ // initial project
986
+ projectContents: """
987
+ <Project Sdk="Microsoft.NET.Sdk">
988
+ <Import Project="my-properties.props" />
989
+
990
+ <PropertyGroup>
991
+ <TargetFramework>netstandard2.0</TargetFramework>
992
+ </PropertyGroup>
993
+
994
+ <ItemGroup>
995
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
996
+ </ItemGroup>
997
+ </Project>
998
+ """,
999
+ additionalFiles: new[]
1000
+ {
1001
+ // initial props file
1002
+ ("my-properties.props", """
1003
+ <Project>
1004
+ <PropertyGroup>
1005
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
1006
+ </PropertyGroup>
1007
+ </Project>
1008
+ """)
1009
+ },
1010
+ // expected project
1011
+ expectedProjectContents: """
1012
+ <Project Sdk="Microsoft.NET.Sdk">
1013
+ <Import Project="my-properties.props" />
1014
+
1015
+ <PropertyGroup>
1016
+ <TargetFramework>netstandard2.0</TargetFramework>
1017
+ </PropertyGroup>
1018
+
1019
+ <ItemGroup>
1020
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
1021
+ </ItemGroup>
1022
+ </Project>
1023
+ """,
1024
+ additionalFilesExpected: new[]
1025
+ {
1026
+ // expected props file
1027
+ ("my-properties.props", """
1028
+ <Project>
1029
+ <PropertyGroup>
1030
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
1031
+ </PropertyGroup>
1032
+ </Project>
1033
+ """)
1034
+ });
1035
+ }
1036
+
1037
+ [Fact]
1038
+ public async Task UpdatePropertyValue_InProps_ForPackageVersion()
1039
+ {
1040
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
1041
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
1042
+ // initial
1043
+ projectContents: """
1044
+ <Project Sdk="Microsoft.NET.Sdk">
1045
+ <PropertyGroup>
1046
+ <TargetFramework>netstandard2.0</TargetFramework>
1047
+ </PropertyGroup>
1048
+
1049
+ <ItemGroup>
1050
+ <PackageReference Include="Newtonsoft.Json" />
1051
+ </ItemGroup>
1052
+ </Project>
1053
+ """,
1054
+ additionalFiles: new[]
1055
+ {
1056
+ // initial props files
1057
+ ("Directory.Packages.props", """
1058
+ <Project>
1059
+ <Import Project="Version.props" />
1060
+ <PropertyGroup>
1061
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1062
+ </PropertyGroup>
1063
+
1064
+ <ItemGroup>
1065
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
1066
+ </ItemGroup>
1067
+ </Project>
1068
+ """),
1069
+ ("Version.props", """
1070
+ <Project>
1071
+ <PropertyGroup>
1072
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
1073
+ </PropertyGroup>
1074
+ </Project>
1075
+ """)
1076
+ },
1077
+ // expected
1078
+ expectedProjectContents: """
1079
+ <Project Sdk="Microsoft.NET.Sdk">
1080
+ <PropertyGroup>
1081
+ <TargetFramework>netstandard2.0</TargetFramework>
1082
+ </PropertyGroup>
1083
+
1084
+ <ItemGroup>
1085
+ <PackageReference Include="Newtonsoft.Json" />
1086
+ </ItemGroup>
1087
+ </Project>
1088
+ """,
1089
+ additionalFilesExpected: new[]
1090
+ {
1091
+ // expected props files
1092
+ ("Directory.Packages.props", """
1093
+ <Project>
1094
+ <Import Project="Version.props" />
1095
+ <PropertyGroup>
1096
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1097
+ </PropertyGroup>
1098
+
1099
+ <ItemGroup>
1100
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
1101
+ </ItemGroup>
1102
+ </Project>
1103
+ """),
1104
+ ("Version.props", """
1105
+ <Project>
1106
+ <PropertyGroup>
1107
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
1108
+ </PropertyGroup>
1109
+ </Project>
1110
+ """)
1111
+ });
1112
+ }
1113
+
1114
+ [Fact]
1115
+ public async Task UpdatePropertyValue_InProps_ThenSubstituted_ForPackageVersion()
1116
+ {
1117
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
1118
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
1119
+ // initial
1120
+ projectContents: """
1121
+ <Project Sdk="Microsoft.NET.Sdk">
1122
+ <PropertyGroup>
1123
+ <TargetFramework>netstandard2.0</TargetFramework>
1124
+ </PropertyGroup>
1125
+
1126
+ <ItemGroup>
1127
+ <PackageReference Include="Newtonsoft.Json" />
1128
+ </ItemGroup>
1129
+ </Project>
1130
+ """,
1131
+ additionalFiles: new[]
1132
+ {
1133
+ // initial props files
1134
+ ("Directory.Packages.props", """
1135
+ <Project>
1136
+ <Import Project="Version.props" />
1137
+ <PropertyGroup>
1138
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1139
+ <NewtonsoftJsonPackageVersion>$(NewtonsoftJsonVersion)</NewtonsoftJsonPackageVersion>
1140
+ </PropertyGroup>
1141
+
1142
+ <ItemGroup>
1143
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
1144
+ </ItemGroup>
1145
+ </Project>
1146
+ """),
1147
+ ("Version.props", """
1148
+ <Project>
1149
+ <PropertyGroup>
1150
+ <NewtonsoftJsonVersion>9.0.1</NewtonsoftJsonVersion>
1151
+ </PropertyGroup>
1152
+ </Project>
1153
+ """)
1154
+ },
1155
+ // expected
1156
+ expectedProjectContents: """
1157
+ <Project Sdk="Microsoft.NET.Sdk">
1158
+ <PropertyGroup>
1159
+ <TargetFramework>netstandard2.0</TargetFramework>
1160
+ </PropertyGroup>
1161
+
1162
+ <ItemGroup>
1163
+ <PackageReference Include="Newtonsoft.Json" />
1164
+ </ItemGroup>
1165
+ </Project>
1166
+ """,
1167
+ additionalFilesExpected: new[]
1168
+ {
1169
+ // expected props files
1170
+ ("Directory.Packages.props", """
1171
+ <Project>
1172
+ <Import Project="Version.props" />
1173
+ <PropertyGroup>
1174
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1175
+ <NewtonsoftJsonPackageVersion>$(NewtonsoftJsonVersion)</NewtonsoftJsonPackageVersion>
1176
+ </PropertyGroup>
1177
+
1178
+ <ItemGroup>
1179
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
1180
+ </ItemGroup>
1181
+ </Project>
1182
+ """),
1183
+ ("Version.props", """
1184
+ <Project>
1185
+ <PropertyGroup>
1186
+ <NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
1187
+ </PropertyGroup>
1188
+ </Project>
1189
+ """)
1190
+ });
1191
+ }
1192
+
1193
+ [Fact]
1194
+ public async Task UpdatePropertyValues_InProps_ThenRedefinedAndSubstituted_ForPackageVersion()
1195
+ {
1196
+ // update Newtonsoft.Json from 9.0.1 to 13.0.1
1197
+ await TestUpdateForProject("Newtonsoft.Json", "9.0.1", "13.0.1",
1198
+ // initial
1199
+ projectContents: """
1200
+ <Project Sdk="Microsoft.NET.Sdk">
1201
+ <PropertyGroup>
1202
+ <TargetFramework>netstandard2.0</TargetFramework>
1203
+ </PropertyGroup>
1204
+
1205
+ <ItemGroup>
1206
+ <PackageReference Include="Newtonsoft.Json" />
1207
+ </ItemGroup>
1208
+ </Project>
1209
+ """,
1210
+ additionalFiles: new[]
1211
+ {
1212
+ // initial props files
1213
+ ("Directory.Packages.props", """
1214
+ <Project>
1215
+ <Import Project="Version.props" />
1216
+ <PropertyGroup>
1217
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1218
+ <NewtonsoftJsonPackageVersion>$(NewtonsoftJsonVersion)</NewtonsoftJsonPackageVersion>
1219
+ </PropertyGroup>
1220
+
1221
+ <ItemGroup>
1222
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
1223
+ </ItemGroup>
1224
+ </Project>
1225
+ """),
1226
+ ("Version.props", """
1227
+ <Project>
1228
+ <PropertyGroup>
1229
+ <NewtonsoftJSONVersion>9.0.1</NewtonsoftJSONVersion>
1230
+ <NewtonsoftJsonPackageVersion>9.0.1</NewtonsoftJsonPackageVersion>
1231
+ </PropertyGroup>
1232
+ </Project>
1233
+ """)
1234
+ },
1235
+ // expected
1236
+ expectedProjectContents: """
1237
+ <Project Sdk="Microsoft.NET.Sdk">
1238
+ <PropertyGroup>
1239
+ <TargetFramework>netstandard2.0</TargetFramework>
1240
+ </PropertyGroup>
1241
+
1242
+ <ItemGroup>
1243
+ <PackageReference Include="Newtonsoft.Json" />
1244
+ </ItemGroup>
1245
+ </Project>
1246
+ """,
1247
+ additionalFilesExpected: new[]
1248
+ {
1249
+ // expected props files
1250
+ ("Directory.Packages.props", """
1251
+ <Project>
1252
+ <Import Project="Version.props" />
1253
+ <PropertyGroup>
1254
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1255
+ <NewtonsoftJsonPackageVersion>$(NewtonsoftJsonVersion)</NewtonsoftJsonPackageVersion>
1256
+ </PropertyGroup>
1257
+
1258
+ <ItemGroup>
1259
+ <PackageVersion Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
1260
+ </ItemGroup>
1261
+ </Project>
1262
+ """),
1263
+ ("Version.props", """
1264
+ <Project>
1265
+ <PropertyGroup>
1266
+ <NewtonsoftJSONVersion>13.0.1</NewtonsoftJSONVersion>
1267
+ <NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
1268
+ </PropertyGroup>
1269
+ </Project>
1270
+ """)
1271
+ });
1272
+ }
1273
+
1274
+ [Fact]
1275
+ public async Task UpdatePeerDependencyWithInlineVersion()
1276
+ {
1277
+ await TestUpdateForProject("Microsoft.Extensions.Http", "2.2.0", "7.0.0",
1278
+ projectContents: """
1279
+ <Project Sdk="Microsoft.NET.Sdk">
1280
+ <PropertyGroup>
1281
+ <TargetFramework>netstandard2.0</TargetFramework>
1282
+ </PropertyGroup>
1283
+ <ItemGroup>
1284
+ <PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" />
1285
+ <PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
1286
+ </ItemGroup>
1287
+ </Project>
1288
+ """,
1289
+ expectedProjectContents: """
1290
+ <Project Sdk="Microsoft.NET.Sdk">
1291
+ <PropertyGroup>
1292
+ <TargetFramework>netstandard2.0</TargetFramework>
1293
+ </PropertyGroup>
1294
+ <ItemGroup>
1295
+ <PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
1296
+ <PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
1297
+ </ItemGroup>
1298
+ </Project>
1299
+ """);
1300
+ }
1301
+
1302
+ [Fact]
1303
+ public async Task UpdatePeerDependencyFromPropertyInSameFile()
1304
+ {
1305
+ await TestUpdateForProject("Microsoft.Extensions.Http", "2.2.0", "7.0.0",
1306
+ projectContents: """
1307
+ <Project Sdk="Microsoft.NET.Sdk">
1308
+ <PropertyGroup>
1309
+ <TargetFramework>netstandard2.0</TargetFramework>
1310
+ <MicrosoftExtensionsHttpVersion>2.2.0</MicrosoftExtensionsHttpVersion>
1311
+ <MicrosoftExtensionsLoggingVersion>2.2.0</MicrosoftExtensionsLoggingVersion>
1312
+ </PropertyGroup>
1313
+ <ItemGroup>
1314
+ <PackageReference Include="Microsoft.Extensions.Http" Version="$(MicrosoftExtensionsHttpVersion)" />
1315
+ <PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
1316
+ </ItemGroup>
1317
+ </Project>
1318
+ """,
1319
+ expectedProjectContents: """
1320
+ <Project Sdk="Microsoft.NET.Sdk">
1321
+ <PropertyGroup>
1322
+ <TargetFramework>netstandard2.0</TargetFramework>
1323
+ <MicrosoftExtensionsHttpVersion>7.0.0</MicrosoftExtensionsHttpVersion>
1324
+ <MicrosoftExtensionsLoggingVersion>7.0.0</MicrosoftExtensionsLoggingVersion>
1325
+ </PropertyGroup>
1326
+ <ItemGroup>
1327
+ <PackageReference Include="Microsoft.Extensions.Http" Version="$(MicrosoftExtensionsHttpVersion)" />
1328
+ <PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
1329
+ </ItemGroup>
1330
+ </Project>
1331
+ """);
1332
+ }
1333
+
1334
+ [Fact]
1335
+ public async Task UpdatePeerDependencyFromPropertyInDifferentFile()
1336
+ {
1337
+ await TestUpdateForProject("Microsoft.Extensions.Http", "2.2.0", "7.0.0",
1338
+ projectContents: """
1339
+ <Project Sdk="Microsoft.NET.Sdk">
1340
+ <Import Project="Versions.props" />
1341
+ <PropertyGroup>
1342
+ <TargetFramework>netstandard2.0</TargetFramework>
1343
+ </PropertyGroup>
1344
+ <ItemGroup>
1345
+ <PackageReference Include="Microsoft.Extensions.Http" Version="$(MicrosoftExtensionsHttpVersion)" />
1346
+ <PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
1347
+ </ItemGroup>
1348
+ </Project>
1349
+ """,
1350
+ additionalFiles: new[]
1351
+ {
1352
+ ("Versions.props", """
1353
+ <Project>
1354
+ <PropertyGroup>
1355
+ <MicrosoftExtensionsHttpVersion>2.2.0</MicrosoftExtensionsHttpVersion>
1356
+ <MicrosoftExtensionsLoggingVersion>2.2.0</MicrosoftExtensionsLoggingVersion>
1357
+ </PropertyGroup>
1358
+ </Project>
1359
+ """)
1360
+ },
1361
+ expectedProjectContents: """
1362
+ <Project Sdk="Microsoft.NET.Sdk">
1363
+ <Import Project="Versions.props" />
1364
+ <PropertyGroup>
1365
+ <TargetFramework>netstandard2.0</TargetFramework>
1366
+ </PropertyGroup>
1367
+ <ItemGroup>
1368
+ <PackageReference Include="Microsoft.Extensions.Http" Version="$(MicrosoftExtensionsHttpVersion)" />
1369
+ <PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
1370
+ </ItemGroup>
1371
+ </Project>
1372
+ """,
1373
+ additionalFilesExpected: new[]
1374
+ {
1375
+ ("Versions.props", """
1376
+ <Project>
1377
+ <PropertyGroup>
1378
+ <MicrosoftExtensionsHttpVersion>7.0.0</MicrosoftExtensionsHttpVersion>
1379
+ <MicrosoftExtensionsLoggingVersion>7.0.0</MicrosoftExtensionsLoggingVersion>
1380
+ </PropertyGroup>
1381
+ </Project>
1382
+ """)
1383
+ });
1384
+ }
1385
+
1386
+ [Fact]
1387
+ public async Task UpdatePeerDependencyWithInlineVersionAndMultipleTfms()
1388
+ {
1389
+ await TestUpdateForProject("Microsoft.Extensions.Http", "2.2.0", "7.0.0",
1390
+ projectContents: """
1391
+ <Project Sdk="Microsoft.NET.Sdk">
1392
+ <PropertyGroup>
1393
+ <TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
1394
+ </PropertyGroup>
1395
+ <ItemGroup>
1396
+ <PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" />
1397
+ <PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
1398
+ </ItemGroup>
1399
+ </Project>
1400
+ """,
1401
+ expectedProjectContents: """
1402
+ <Project Sdk="Microsoft.NET.Sdk">
1403
+ <PropertyGroup>
1404
+ <TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
1405
+ </PropertyGroup>
1406
+ <ItemGroup>
1407
+ <PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
1408
+ <PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
1409
+ </ItemGroup>
1410
+ </Project>
1411
+ """);
1412
+ }
1413
+
1414
+ [Fact]
1415
+ public async Task NoUpdateForPeerDependenciesWhichAreHigherVersion()
1416
+ {
1417
+ await TestUpdateForProject("Microsoft.Identity.Web", "2.13.0", "2.13.2",
1418
+ projectContents: """
1419
+ <Project Sdk="Microsoft.NET.Sdk">
1420
+ <PropertyGroup>
1421
+ <TargetFramework>netstandard2.0</TargetFramework>
1422
+ </PropertyGroup>
1423
+ <ItemGroup>
1424
+ <PackageReference Include="Azure.Identity" />
1425
+ <PackageReference Include="Azure.Security.KeyVault.Keys" />
1426
+ <PackageReference Include="Azure.Security.KeyVault.Secrets" />
1427
+ <PackageReference Include="Microsoft.Identity.Web" />
1428
+ </ItemGroup>
1429
+ </Project>
1430
+ """,
1431
+ additionalFiles: new[]
1432
+ {
1433
+ ("Directory.Packages.props", """
1434
+ <Project>
1435
+ <PropertyGroup>
1436
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1437
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
1438
+ </PropertyGroup>
1439
+ <ItemGroup>
1440
+ <PackageVersion Include="Azure.Identity" Version="1.9.0" />
1441
+ <PackageVersion Include="Azure.Security.KeyVault.Keys" Version="4.5.0" />
1442
+ <PackageVersion Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
1443
+ <PackageVersion Include="Microsoft.Identity.Web" Version="2.13.0" />
1444
+ </ItemGroup>
1445
+ </Project>
1446
+ """)
1447
+ },
1448
+ expectedProjectContents: """
1449
+ <Project Sdk="Microsoft.NET.Sdk">
1450
+ <PropertyGroup>
1451
+ <TargetFramework>netstandard2.0</TargetFramework>
1452
+ </PropertyGroup>
1453
+ <ItemGroup>
1454
+ <PackageReference Include="Azure.Identity" />
1455
+ <PackageReference Include="Azure.Security.KeyVault.Keys" />
1456
+ <PackageReference Include="Azure.Security.KeyVault.Secrets" />
1457
+ <PackageReference Include="Microsoft.Identity.Web" />
1458
+ </ItemGroup>
1459
+ </Project>
1460
+ """,
1461
+ additionalFilesExpected: new[]
1462
+ {
1463
+ ("Directory.Packages.props", """
1464
+ <Project>
1465
+ <PropertyGroup>
1466
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1467
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
1468
+ </PropertyGroup>
1469
+ <ItemGroup>
1470
+ <PackageVersion Include="Azure.Identity" Version="1.9.0" />
1471
+ <PackageVersion Include="Azure.Security.KeyVault.Keys" Version="4.5.0" />
1472
+ <PackageVersion Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
1473
+ <PackageVersion Include="Microsoft.Identity.Web" Version="2.13.2" />
1474
+ </ItemGroup>
1475
+ </Project>
1476
+ """)
1477
+ });
1478
+ }
1479
+
1480
+ [Fact]
1481
+ public async Task UpdatingToNotCompatiblePackageDoesNothing()
1482
+ {
1483
+ await TestUpdateForProject("Microsoft.AspNetCore.Authentication.JwtBearer", "3.1.18", "7.0.5",
1484
+ projectContents: """
1485
+ <Project Sdk="Microsoft.NET.Sdk">
1486
+ <PropertyGroup>
1487
+ <TargetFramework>netcoreapp3.1</TargetFramework>
1488
+ </PropertyGroup>
1489
+ <ItemGroup>
1490
+ <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.18" />
1491
+ </ItemGroup>
1492
+ </Project>
1493
+ """,
1494
+ expectedProjectContents: """
1495
+ <Project Sdk="Microsoft.NET.Sdk">
1496
+ <PropertyGroup>
1497
+ <TargetFramework>netcoreapp3.1</TargetFramework>
1498
+ </PropertyGroup>
1499
+ <ItemGroup>
1500
+ <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.18" />
1501
+ </ItemGroup>
1502
+ </Project>
1503
+ """);
1504
+ }
1505
+
1506
+ [Fact]
1507
+ public async Task UpdatingToNotCompatiblePackageDoesNothingWithSingleOfMultileTfmNotSupported()
1508
+ {
1509
+ // the requested package upgrade is supported on net7.0, but not netcoreapp3.1, so we skip the whole thing
1510
+ await TestUpdateForProject("Microsoft.AspNetCore.Authentication.JwtBearer", "3.1.18", "7.0.5",
1511
+ projectContents: """
1512
+ <Project Sdk="Microsoft.NET.Sdk">
1513
+ <PropertyGroup>
1514
+ <TargetFrameworks>netcoreapp3.1;net7.0</TargetFrameworks>
1515
+ </PropertyGroup>
1516
+ <ItemGroup>
1517
+ <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.18" />
1518
+ </ItemGroup>
1519
+ </Project>
1520
+ """,
1521
+ expectedProjectContents: """
1522
+ <Project Sdk="Microsoft.NET.Sdk">
1523
+ <PropertyGroup>
1524
+ <TargetFrameworks>netcoreapp3.1;net7.0</TargetFrameworks>
1525
+ </PropertyGroup>
1526
+ <ItemGroup>
1527
+ <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.18" />
1528
+ </ItemGroup>
1529
+ </Project>
1530
+ """);
1531
+ }
1532
+
1533
+ [Fact]
1534
+ public async Task UpdateOfNonExistantPackageDoesNothingEvenIfTransitiveDependencyIsPresent()
1535
+ {
1536
+ // package Microsoft.Extensions.Http isn't present, but one of its transitive dependencies is
1537
+ await TestUpdateForProject("Microsoft.Extensions.Http", "2.2.0", "7.0.0",
1538
+ projectContents: """
1539
+ <Project Sdk="Microsoft.NET.Sdk">
1540
+ <PropertyGroup>
1541
+ <TargetFramework>netstandard2.0</TargetFramework>
1542
+ </PropertyGroup>
1543
+ <ItemGroup>
1544
+ <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
1545
+ </ItemGroup>
1546
+ </Project>
1547
+ """,
1548
+ expectedProjectContents: """
1549
+ <Project Sdk="Microsoft.NET.Sdk">
1550
+ <PropertyGroup>
1551
+ <TargetFramework>netstandard2.0</TargetFramework>
1552
+ </PropertyGroup>
1553
+ <ItemGroup>
1554
+ <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
1555
+ </ItemGroup>
1556
+ </Project>
1557
+ """);
1558
+ }
1559
+
1560
+ [Fact]
1561
+ public async Task AvoidPackageDowngradeWhenUpdatingDependency()
1562
+ {
1563
+ await TestUpdateForProject("Microsoft.VisualStudio.Sdk.TestFramework.Xunit", "17.2.7", "17.6.16",
1564
+ projectContents: """
1565
+ <Project Sdk="Microsoft.NET.Sdk">
1566
+
1567
+ <PropertyGroup>
1568
+ <TargetFramework>$(PreferredTargetFramework)</TargetFramework>
1569
+ <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
1570
+ <RootNamespace />
1571
+ </PropertyGroup>
1572
+
1573
+ <ItemGroup>
1574
+ <PackageReference Include="Microsoft.NET.Test.Sdk" />
1575
+ <PackageReference Include="Microsoft.VisualStudio.Sdk.TestFramework" />
1576
+ <PackageReference Include="Microsoft.VisualStudio.Sdk.TestFramework.Xunit" />
1577
+ <PackageReference Include="Moq" />
1578
+ <PackageReference Include="xunit.runner.visualstudio" />
1579
+ <PackageReference Include="xunit" />
1580
+ </ItemGroup>
1581
+
1582
+ </Project>
1583
+ """,
1584
+ additionalFiles: new[]
1585
+ {
1586
+ ("Directory.Packages.props", """
1587
+ <Project>
1588
+ <PropertyGroup>
1589
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1590
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
1591
+ </PropertyGroup>
1592
+ <ItemGroup>
1593
+ <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
1594
+ <PackageVersion Include="Microsoft.VisualStudio.Sdk.TestFramework" Version="17.2.7" />
1595
+ <PackageVersion Include="Microsoft.VisualStudio.Sdk.TestFramework.Xunit" Version="17.2.7" />
1596
+ <PackageVersion Include="Microsoft.VisualStudio.Shell.15.0" Version="17.6.36389" />
1597
+ <PackageVersion Include="Microsoft.VisualStudio.Text.Data" Version="17.6.268" />
1598
+ <PackageVersion Include="Moq" Version="4.18.2" />
1599
+ <PackageVersion Include="xunit" Version="2.5.0" />
1600
+ <PackageVersion Include="xunit.runner.visualstudio" Version="2.5.0" />
1601
+ </ItemGroup>
1602
+ </Project>
1603
+ """),
1604
+ ("Directory.Build.props", """
1605
+ <Project>
1606
+ <PropertyGroup>
1607
+ <PreferredTargetFramework>net7.0</PreferredTargetFramework>
1608
+ </PropertyGroup>
1609
+ </Project>
1610
+ """)
1611
+ },
1612
+ expectedProjectContents: """
1613
+ <Project Sdk="Microsoft.NET.Sdk">
1614
+
1615
+ <PropertyGroup>
1616
+ <TargetFramework>$(PreferredTargetFramework)</TargetFramework>
1617
+ <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
1618
+ <RootNamespace />
1619
+ </PropertyGroup>
1620
+
1621
+ <ItemGroup>
1622
+ <PackageReference Include="Microsoft.NET.Test.Sdk" />
1623
+ <PackageReference Include="Microsoft.VisualStudio.Sdk.TestFramework" />
1624
+ <PackageReference Include="Microsoft.VisualStudio.Sdk.TestFramework.Xunit" />
1625
+ <PackageReference Include="Moq" />
1626
+ <PackageReference Include="xunit.runner.visualstudio" />
1627
+ <PackageReference Include="xunit" />
1628
+ </ItemGroup>
1629
+
1630
+ </Project>
1631
+ """,
1632
+ additionalFilesExpected: new[]
1633
+ {
1634
+ ("Directory.Packages.props", """
1635
+ <Project>
1636
+ <PropertyGroup>
1637
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1638
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
1639
+ </PropertyGroup>
1640
+ <ItemGroup>
1641
+ <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
1642
+ <PackageVersion Include="Microsoft.VisualStudio.Sdk.TestFramework" Version="17.6.16" />
1643
+ <PackageVersion Include="Microsoft.VisualStudio.Sdk.TestFramework.Xunit" Version="17.6.16" />
1644
+ <PackageVersion Include="Microsoft.VisualStudio.Shell.15.0" Version="17.6.36389" />
1645
+ <PackageVersion Include="Microsoft.VisualStudio.Text.Data" Version="17.6.268" />
1646
+ <PackageVersion Include="Moq" Version="4.18.4" />
1647
+ <PackageVersion Include="xunit" Version="2.5.0" />
1648
+ <PackageVersion Include="xunit.runner.visualstudio" Version="2.5.0" />
1649
+ </ItemGroup>
1650
+ </Project>
1651
+ """),
1652
+ ("Directory.Build.props", """
1653
+ <Project>
1654
+ <PropertyGroup>
1655
+ <PreferredTargetFramework>net7.0</PreferredTargetFramework>
1656
+ </PropertyGroup>
1657
+ </Project>
1658
+ """)
1659
+ });
1660
+ }
1661
+
1662
+ [Fact]
1663
+ public async Task AddTransitiveDependencyByAddingPackageReferenceAndVersion()
1664
+ {
1665
+ await TestUpdateForProject("System.Text.Json", "5.0.0", "5.0.2", isTransitive: true,
1666
+ // initial
1667
+ projectContents: """
1668
+ <Project Sdk="Microsoft.NET.Sdk">
1669
+
1670
+ <PropertyGroup>
1671
+ <TargetFramework>net5.0</TargetFramework>
1672
+ </PropertyGroup>
1673
+
1674
+ <ItemGroup>
1675
+ <PackageReference Include="Mongo2Go" />
1676
+ </ItemGroup>
1677
+
1678
+ </Project>
1679
+ """,
1680
+ additionalFiles: new[]
1681
+ {
1682
+ // initial props files
1683
+ ("Directory.Packages.props", """
1684
+ <Project>
1685
+ <PropertyGroup>
1686
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1687
+ </PropertyGroup>
1688
+ <ItemGroup>
1689
+ <PackageVersion Include="Mongo2Go" Version="3.1.3" />
1690
+ </ItemGroup>
1691
+ </Project>
1692
+ """)
1693
+ },
1694
+ // expected
1695
+ expectedProjectContents: """
1696
+ <Project Sdk="Microsoft.NET.Sdk">
1697
+
1698
+ <PropertyGroup>
1699
+ <TargetFramework>net5.0</TargetFramework>
1700
+ </PropertyGroup>
1701
+
1702
+ <ItemGroup>
1703
+ <PackageReference Include="Mongo2Go" />
1704
+ <PackageReference Include="System.Text.Json" />
1705
+ </ItemGroup>
1706
+
1707
+ </Project>
1708
+ """,
1709
+ additionalFilesExpected: new[]
1710
+ {
1711
+ // expected props files
1712
+ ("Directory.Packages.props", """
1713
+ <Project>
1714
+ <PropertyGroup>
1715
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1716
+ </PropertyGroup>
1717
+ <ItemGroup>
1718
+ <PackageVersion Include="Mongo2Go" Version="3.1.3" />
1719
+ <PackageVersion Include="System.Text.Json" Version="5.0.2" />
1720
+ </ItemGroup>
1721
+ </Project>
1722
+ """)
1723
+ });
1724
+ }
1725
+
1726
+ [Fact]
1727
+ public async Task PinTransitiveDependencyByAddingPackageVersion()
1728
+ {
1729
+ await TestUpdateForProject("System.Text.Json", "5.0.0", "5.0.2", isTransitive: true,
1730
+ // initial
1731
+ projectContents: """
1732
+ <Project Sdk="Microsoft.NET.Sdk">
1733
+
1734
+ <PropertyGroup>
1735
+ <NoWarn>$(NoWarn);NETSDK1138</NoWarn>
1736
+ <TargetFramework>net5.0</TargetFramework>
1737
+ </PropertyGroup>
1738
+
1739
+ <ItemGroup>
1740
+ <PackageReference Include="Mongo2Go" />
1741
+ </ItemGroup>
1742
+
1743
+ </Project>
1744
+ """,
1745
+ additionalFiles: new[]
1746
+ {
1747
+ // initial props files
1748
+ ("Directory.Packages.props", """
1749
+ <Project>
1750
+ <PropertyGroup>
1751
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1752
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
1753
+ </PropertyGroup>
1754
+ <ItemGroup>
1755
+ <PackageVersion Include="Mongo2Go" Version="3.1.3" />
1756
+ </ItemGroup>
1757
+ </Project>
1758
+ """)
1759
+ },
1760
+ // expected
1761
+ expectedProjectContents: """
1762
+ <Project Sdk="Microsoft.NET.Sdk">
1763
+
1764
+ <PropertyGroup>
1765
+ <NoWarn>$(NoWarn);NETSDK1138</NoWarn>
1766
+ <TargetFramework>net5.0</TargetFramework>
1767
+ </PropertyGroup>
1768
+
1769
+ <ItemGroup>
1770
+ <PackageReference Include="Mongo2Go" />
1771
+ </ItemGroup>
1772
+
1773
+ </Project>
1774
+ """,
1775
+ additionalFilesExpected: new[]
1776
+ {
1777
+ // expected props files
1778
+ ("Directory.Packages.props", """
1779
+ <Project>
1780
+ <PropertyGroup>
1781
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1782
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
1783
+ </PropertyGroup>
1784
+ <ItemGroup>
1785
+ <PackageVersion Include="Mongo2Go" Version="3.1.3" />
1786
+ <PackageVersion Include="System.Text.Json" Version="5.0.2" />
1787
+ </ItemGroup>
1788
+ </Project>
1789
+ """)
1790
+ });
1791
+ }
1792
+
1793
+ [Fact]
1794
+ public async Task PropsFileNameWithDifferentCasing()
1795
+ {
1796
+ await TestUpdateForProject("Newtonsoft.Json", "12.0.1", "13.0.1",
1797
+ projectContents: """
1798
+ <Project Sdk="Microsoft.NET.Sdk">
1799
+ <PropertyGroup>
1800
+ <TargetFramework>net7.0</TargetFramework>
1801
+ </PropertyGroup>
1802
+ <ItemGroup>
1803
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
1804
+ </ItemGroup>
1805
+ </Project>
1806
+ """,
1807
+ additionalFiles: new[]
1808
+ {
1809
+ ("Directory.Build.props", """
1810
+ <Project>
1811
+ <Import Project="Versions.Props" />
1812
+ </Project>
1813
+ """),
1814
+ // notice the uppercase 'P' in the file name
1815
+ ("Versions.Props", """
1816
+ <Project>
1817
+ <PropertyGroup>
1818
+ <NewtonsoftJsonVersion>12.0.1</NewtonsoftJsonVersion>
1819
+ </PropertyGroup>
1820
+ </Project>
1821
+ """)
1822
+ },
1823
+ // no change
1824
+ expectedProjectContents: """
1825
+ <Project Sdk="Microsoft.NET.Sdk">
1826
+ <PropertyGroup>
1827
+ <TargetFramework>net7.0</TargetFramework>
1828
+ </PropertyGroup>
1829
+ <ItemGroup>
1830
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
1831
+ </ItemGroup>
1832
+ </Project>
1833
+ """,
1834
+ additionalFilesExpected: new[]
1835
+ {
1836
+ // no change
1837
+ ("Directory.Build.props", """
1838
+ <Project>
1839
+ <Import Project="Versions.Props" />
1840
+ </Project>
1841
+ """),
1842
+ // version number was updated here
1843
+ ("Versions.Props", """
1844
+ <Project>
1845
+ <PropertyGroup>
1846
+ <NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
1847
+ </PropertyGroup>
1848
+ </Project>
1849
+ """)
1850
+ }
1851
+ );
1852
+ }
1853
+
1854
+ [Fact]
1855
+ public async Task VersionAttributeWithDifferentCasing_VersionNumberInline()
1856
+ {
1857
+ // the version attribute in the project has an all lowercase name
1858
+ await TestUpdateForProject("Newtonsoft.Json", "12.0.1", "13.0.1",
1859
+ projectContents: """
1860
+ <Project Sdk="Microsoft.NET.Sdk">
1861
+ <PropertyGroup>
1862
+ <TargetFramework>net7.0</TargetFramework>
1863
+ </PropertyGroup>
1864
+ <ItemGroup>
1865
+ <PackageReference Include="Newtonsoft.Json" version="12.0.1" />
1866
+ </ItemGroup>
1867
+ </Project>
1868
+ """,
1869
+ expectedProjectContents: """
1870
+ <Project Sdk="Microsoft.NET.Sdk">
1871
+ <PropertyGroup>
1872
+ <TargetFramework>net7.0</TargetFramework>
1873
+ </PropertyGroup>
1874
+ <ItemGroup>
1875
+ <PackageReference Include="Newtonsoft.Json" version="13.0.1" />
1876
+ </ItemGroup>
1877
+ </Project>
1878
+ """
1879
+ );
1880
+ }
1881
+
1882
+ [Fact]
1883
+ public async Task VersionAttributeWithDifferentCasing_VersionNumberInProperty()
1884
+ {
1885
+ // the version attribute in the project has an all lowercase name
1886
+ await TestUpdateForProject("Newtonsoft.Json", "12.0.1", "13.0.1",
1887
+ projectContents: """
1888
+ <Project Sdk="Microsoft.NET.Sdk">
1889
+ <PropertyGroup>
1890
+ <TargetFramework>net7.0</TargetFramework>
1891
+ </PropertyGroup>
1892
+ <ItemGroup>
1893
+ <PackageReference Include="Newtonsoft.Json" version="$(NewtonsoftJsonVersion)" />
1894
+ </ItemGroup>
1895
+ </Project>
1896
+ """,
1897
+ additionalFiles: new[]
1898
+ {
1899
+ ("Directory.Build.props", """
1900
+ <Project>
1901
+ <Import Project="Versions.props" />
1902
+ </Project>
1903
+ """),
1904
+ ("Versions.props", """
1905
+ <Project>
1906
+ <PropertyGroup>
1907
+ <NewtonsoftJsonVersion>12.0.1</NewtonsoftJsonVersion>
1908
+ </PropertyGroup>
1909
+ </Project>
1910
+ """)
1911
+ },
1912
+ // no change
1913
+ expectedProjectContents: """
1914
+ <Project Sdk="Microsoft.NET.Sdk">
1915
+ <PropertyGroup>
1916
+ <TargetFramework>net7.0</TargetFramework>
1917
+ </PropertyGroup>
1918
+ <ItemGroup>
1919
+ <PackageReference Include="Newtonsoft.Json" version="$(NewtonsoftJsonVersion)" />
1920
+ </ItemGroup>
1921
+ </Project>
1922
+ """,
1923
+ additionalFilesExpected: new[]
1924
+ {
1925
+ // no change
1926
+ ("Directory.Build.props", """
1927
+ <Project>
1928
+ <Import Project="Versions.props" />
1929
+ </Project>
1930
+ """),
1931
+ // version number was updated here
1932
+ ("Versions.props", """
1933
+ <Project>
1934
+ <PropertyGroup>
1935
+ <NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
1936
+ </PropertyGroup>
1937
+ </Project>
1938
+ """)
1939
+ }
1940
+ );
1941
+ }
1942
+
1943
+ [Fact]
1944
+ public async Task DirectoryPackagesPropsDoesCentralPackagePinningGetsUpdatedIfTransitiveFlagIsSet()
1945
+ {
1946
+ await TestUpdateForProject("xunit.assert", "2.5.2", "2.5.3",
1947
+ isTransitive: true,
1948
+ projectContents: """
1949
+ <Project Sdk="Microsoft.NET.Sdk">
1950
+ <PropertyGroup>
1951
+ <TargetFramework>net7.0</TargetFramework>
1952
+ </PropertyGroup>
1953
+ <ItemGroup>
1954
+ <PackageReference Include="xunit" />
1955
+ </ItemGroup>
1956
+ </Project>
1957
+ """,
1958
+ additionalFiles: new[]
1959
+ {
1960
+ ("Directory.Packages.props", """
1961
+ <Project>
1962
+ <PropertyGroup>
1963
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1964
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
1965
+ </PropertyGroup>
1966
+ <ItemGroup>
1967
+ <PackageVersion Include="xunit" Version="2.5.2" />
1968
+ <PackageVersion Include="xunit.assert" Version="2.5.2" />
1969
+ </ItemGroup>
1970
+ </Project>
1971
+ """)
1972
+ },
1973
+ expectedProjectContents: """
1974
+ <Project Sdk="Microsoft.NET.Sdk">
1975
+ <PropertyGroup>
1976
+ <TargetFramework>net7.0</TargetFramework>
1977
+ </PropertyGroup>
1978
+ <ItemGroup>
1979
+ <PackageReference Include="xunit" />
1980
+ </ItemGroup>
1981
+ </Project>
1982
+ """,
1983
+ additionalFilesExpected: new[]
1984
+ {
1985
+ ("Directory.Packages.props", """
1986
+ <Project>
1987
+ <PropertyGroup>
1988
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
1989
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
1990
+ </PropertyGroup>
1991
+ <ItemGroup>
1992
+ <PackageVersion Include="xunit" Version="2.5.2" />
1993
+ <PackageVersion Include="xunit.assert" Version="2.5.3" />
1994
+ </ItemGroup>
1995
+ </Project>
1996
+ """)
1997
+ }
1998
+ );
1999
+ }
2000
+
2001
+ [Fact]
2002
+ public async Task DirectoryPackagesPropsDoesNotGetDuplicateEntryIfCentralTransitivePinningIsUsed()
2003
+ {
2004
+ await TestUpdateForProject("xunit.assert", "2.5.2", "2.5.3",
2005
+ isTransitive: true,
2006
+ projectContents: """
2007
+ <Project Sdk="Microsoft.NET.Sdk">
2008
+ <PropertyGroup>
2009
+ <TargetFramework>net7.0</TargetFramework>
2010
+ </PropertyGroup>
2011
+ <ItemGroup>
2012
+ <PackageReference Include="xunit" />
2013
+ </ItemGroup>
2014
+ </Project>
2015
+ """,
2016
+ additionalFiles: new[]
2017
+ {
2018
+ ("Directory.Packages.props", """
2019
+ <Project>
2020
+ <PropertyGroup>
2021
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
2022
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
2023
+ </PropertyGroup>
2024
+ <ItemGroup>
2025
+ <PackageVersion Include="xunit" Version="2.5.2" />
2026
+ <PackageVersion Include="xunit.assert" Version="2.5.3" />
2027
+ </ItemGroup>
2028
+ </Project>
2029
+ """)
2030
+ },
2031
+ expectedProjectContents: """
2032
+ <Project Sdk="Microsoft.NET.Sdk">
2033
+ <PropertyGroup>
2034
+ <TargetFramework>net7.0</TargetFramework>
2035
+ </PropertyGroup>
2036
+ <ItemGroup>
2037
+ <PackageReference Include="xunit" />
2038
+ </ItemGroup>
2039
+ </Project>
2040
+ """,
2041
+ additionalFilesExpected: new[]
2042
+ {
2043
+ ("Directory.Packages.props", """
2044
+ <Project>
2045
+ <PropertyGroup>
2046
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
2047
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
2048
+ </PropertyGroup>
2049
+ <ItemGroup>
2050
+ <PackageVersion Include="xunit" Version="2.5.2" />
2051
+ <PackageVersion Include="xunit.assert" Version="2.5.3" />
2052
+ </ItemGroup>
2053
+ </Project>
2054
+ """)
2055
+ }
2056
+ );
2057
+ }
2058
+
2059
+ [Fact]
2060
+ public async Task PackageWithFourPartVersionCanBeUpdated()
2061
+ {
2062
+ await TestUpdateForProject("AWSSDK.Core", "3.7.204.13", "3.7.204.14",
2063
+ projectContents: """
2064
+ <Project Sdk="Microsoft.NET.Sdk">
2065
+ <PropertyGroup>
2066
+ <TargetFramework>net7.0</TargetFramework>
2067
+ </PropertyGroup>
2068
+ <ItemGroup>
2069
+ <PackageReference Include="AWSSDK.Core" Version="3.7.204.13" />
2070
+ </ItemGroup>
2071
+ </Project>
2072
+ """,
2073
+ expectedProjectContents: """
2074
+ <Project Sdk="Microsoft.NET.Sdk">
2075
+ <PropertyGroup>
2076
+ <TargetFramework>net7.0</TargetFramework>
2077
+ </PropertyGroup>
2078
+ <ItemGroup>
2079
+ <PackageReference Include="AWSSDK.Core" Version="3.7.204.14" />
2080
+ </ItemGroup>
2081
+ </Project>
2082
+ """
2083
+ );
2084
+ }
2085
+
2086
+ [Fact]
2087
+ public async Task PackageWithOnlyBuildTargetsCanBeUpdated()
2088
+ {
2089
+ await TestUpdateForProject("Microsoft.Windows.Compatibility", "7.0.0", "8.0.0",
2090
+ projectContents: """
2091
+ <Project Sdk="Microsoft.NET.Sdk">
2092
+ <PropertyGroup>
2093
+ <TargetFramework>net5.0</TargetFramework>
2094
+ </PropertyGroup>
2095
+ <ItemGroup>
2096
+ <PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.0" />
2097
+ </ItemGroup>
2098
+ </Project>
2099
+ """,
2100
+ expectedProjectContents: """
2101
+ <Project Sdk="Microsoft.NET.Sdk">
2102
+ <PropertyGroup>
2103
+ <TargetFramework>net5.0</TargetFramework>
2104
+ </PropertyGroup>
2105
+ <ItemGroup>
2106
+ <PackageReference Include="Microsoft.Windows.Compatibility" Version="8.0.0" />
2107
+ </ItemGroup>
2108
+ </Project>
2109
+ """
2110
+ );
2111
+ }
2112
+
2113
+ [Fact]
2114
+ public async Task UpdatePackageVersionFromPropertiesWithAndWithoutConditions()
2115
+ {
2116
+ await TestUpdateForProject("Newtonsoft.Json", "12.0.1", "13.0.1",
2117
+ projectContents: """
2118
+ <Project Sdk="Microsoft.NET.Sdk">
2119
+ <PropertyGroup>
2120
+ <TargetFramework>netstandard2.0</TargetFramework>
2121
+ <NewtonsoftJsonVersion Condition="$(UseLegacyVersion7) == 'true'">7.0.1</NewtonsoftJsonVersion>
2122
+ <NewtonsoftJsonVersion>12.0.1</NewtonsoftJsonVersion>
2123
+ <NewtonsoftJsonVersion Condition="$(UseLegacyVersion9) == 'true'">9.0.1</NewtonsoftJsonVersion>
2124
+ </PropertyGroup>
2125
+ <ItemGroup>
2126
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
2127
+ </ItemGroup>
2128
+ </Project>
2129
+ """,
2130
+ expectedProjectContents: """
2131
+ <Project Sdk="Microsoft.NET.Sdk">
2132
+ <PropertyGroup>
2133
+ <TargetFramework>netstandard2.0</TargetFramework>
2134
+ <NewtonsoftJsonVersion Condition="$(UseLegacyVersion7) == 'true'">7.0.1</NewtonsoftJsonVersion>
2135
+ <NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
2136
+ <NewtonsoftJsonVersion Condition="$(UseLegacyVersion9) == 'true'">9.0.1</NewtonsoftJsonVersion>
2137
+ </PropertyGroup>
2138
+ <ItemGroup>
2139
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
2140
+ </ItemGroup>
2141
+ </Project>
2142
+ """
2143
+ );
2144
+ }
2145
+
2146
+ [Fact]
2147
+ public async Task UpdatePackageVersionFromPropertyWithConditionCheckingForEmptyString()
2148
+ {
2149
+ await TestUpdateForProject("Newtonsoft.Json", "12.0.1", "13.0.1",
2150
+ projectContents: """
2151
+ <Project Sdk="Microsoft.NET.Sdk">
2152
+ <PropertyGroup>
2153
+ <TargetFramework>netstandard2.0</TargetFramework>
2154
+ <NewtonsoftJsonVersion Condition="$(NewtonsoftJsonVersion) == ''">12.0.1</NewtonsoftJsonVersion>
2155
+ <NewtonsoftJsonVersion Condition="$(UseLegacyVersion9) == 'true'">9.0.1</NewtonsoftJsonVersion>
2156
+ </PropertyGroup>
2157
+ <ItemGroup>
2158
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
2159
+ </ItemGroup>
2160
+ </Project>
2161
+ """,
2162
+ expectedProjectContents: """
2163
+ <Project Sdk="Microsoft.NET.Sdk">
2164
+ <PropertyGroup>
2165
+ <TargetFramework>netstandard2.0</TargetFramework>
2166
+ <NewtonsoftJsonVersion Condition="$(NewtonsoftJsonVersion) == ''">13.0.1</NewtonsoftJsonVersion>
2167
+ <NewtonsoftJsonVersion Condition="$(UseLegacyVersion9) == 'true'">9.0.1</NewtonsoftJsonVersion>
2168
+ </PropertyGroup>
2169
+ <ItemGroup>
2170
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
2171
+ </ItemGroup>
2172
+ </Project>
2173
+ """
2174
+ );
2175
+ }
2176
+ }
2177
+ }