dependabot-nuget 0.240.0 → 0.242.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) 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 +23 -0
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +36 -0
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +47 -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 +460 -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 +83 -0
  63. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/XmlExtensions.cs +124 -0
  64. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/DotNetToolsJsonBuildFileTests.cs +53 -0
  65. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +80 -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 +598 -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/metadata_finder.rb +4 -4
  89. metadata +91 -5
@@ -0,0 +1,598 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Collections.Immutable;
4
+ using System.IO;
5
+ using System.Linq;
6
+ using System.Threading.Tasks;
7
+
8
+ using Xunit;
9
+
10
+ namespace NuGetUpdater.Core.Test.Utilities;
11
+
12
+ public class MSBuildHelperTests
13
+ {
14
+ public MSBuildHelperTests()
15
+ {
16
+ MSBuildHelper.RegisterMSBuild();
17
+ }
18
+
19
+ [Fact]
20
+ public void GetRootedValue_FindsValue()
21
+ {
22
+ // Arrange
23
+ var projectContents = """
24
+ <Project>
25
+ <PropertyGroup>
26
+ <TargetFramework>netstandard2.0</TargetFramework>
27
+ </PropertyGroup>
28
+ <ItemGroup>
29
+ <PackageReference Include="Newtonsoft.Json" Version="$(PackageVersion1)" />
30
+ </ItemGroup>
31
+ </Project>
32
+ """;
33
+ var propertyInfo = new Dictionary<string, string>
34
+ {
35
+ { "PackageVersion1", "1.1.1" },
36
+ };
37
+
38
+ // Act
39
+ var rootValue = MSBuildHelper.GetRootedValue(projectContents, propertyInfo);
40
+
41
+ // Assert
42
+ Assert.Equal("""
43
+ <Project>
44
+ <PropertyGroup>
45
+ <TargetFramework>netstandard2.0</TargetFramework>
46
+ </PropertyGroup>
47
+ <ItemGroup>
48
+ <PackageReference Include="Newtonsoft.Json" Version="1.1.1" />
49
+ </ItemGroup>
50
+ </Project>
51
+ """, rootValue);
52
+ }
53
+
54
+ [Fact(Timeout = 1000)]
55
+ public async Task GetRootedValue_DoesNotRecurseAsync()
56
+ {
57
+ // Arrange
58
+ var projectContents = """
59
+ <Project>
60
+ <PropertyGroup>
61
+ <TargetFramework>netstandard2.0</TargetFramework>
62
+ </PropertyGroup>
63
+ <ItemGroup>
64
+ <PackageReference Include="Newtonsoft.Json" Version="$(PackageVersion1)" />
65
+ </ItemGroup>
66
+ </Project>
67
+ """;
68
+ var propertyInfo = new Dictionary<string, string>
69
+ {
70
+ { "PackageVersion1", "$(PackageVersion2)" },
71
+ { "PackageVersion2", "$(PackageVersion1)" }
72
+ };
73
+ // This is needed to make the timeout work. Without that we could get caugth in an infinite loop.
74
+ await Task.Delay(1);
75
+
76
+ // Act
77
+ var ex = Assert.Throws<InvalidDataException>(() => MSBuildHelper.GetRootedValue(projectContents, propertyInfo));
78
+
79
+ // Assert
80
+ Assert.Equal("Property 'PackageVersion1' has a circular reference.", ex.Message);
81
+ }
82
+
83
+ [Theory]
84
+ [MemberData(nameof(SolutionProjectPathTestData))]
85
+ public void ProjectPathsCanBeParsedFromSolutionFiles(string solutionContent, string[] expectedProjectSubPaths)
86
+ {
87
+ var solutionPath = Path.GetTempFileName();
88
+ var solutionDirectory = Path.GetDirectoryName(solutionPath)!;
89
+ try
90
+ {
91
+ File.WriteAllText(solutionPath, solutionContent);
92
+ var actualProjectSubPaths = MSBuildHelper.GetProjectPathsFromSolution(solutionPath).ToArray();
93
+ var expectedPaths = expectedProjectSubPaths.Select(path => Path.Combine(solutionDirectory, path)).ToArray();
94
+ if (Environment.OSVersion.Platform == PlatformID.Win32NT)
95
+ {
96
+ // make the test happy when running on Windows
97
+ expectedPaths = expectedPaths.Select(p => p.Replace("/", "\\")).ToArray();
98
+ }
99
+
100
+ Assert.Equal(expectedPaths, actualProjectSubPaths);
101
+ }
102
+ finally
103
+ {
104
+ File.Delete(solutionPath);
105
+ }
106
+ }
107
+
108
+ [Theory]
109
+ [InlineData("<Project><PropertyGroup><TargetFramework>netstandard2.0</TargetFramework></PropertyGroup></Project>", "netstandard2.0", null)]
110
+ [InlineData("<Project><PropertyGroup><TargetFrameworks>netstandard2.0</TargetFrameworks></PropertyGroup></Project>", "netstandard2.0", null)]
111
+ [InlineData("<Project><PropertyGroup><TargetFrameworks> ; netstandard2.0 ; </TargetFrameworks></PropertyGroup></Project>", "netstandard2.0", null)]
112
+ [InlineData("<Project><PropertyGroup><TargetFrameworks>netstandard2.0 ; netstandard2.1 ; </TargetFrameworks></PropertyGroup></Project>", "netstandard2.0", "netstandard2.1")]
113
+ public void TfmsCanBeDeterminedFromProjectContents(string projectContents, string? expectedTfm1, string? expectedTfm2)
114
+ {
115
+ var projectPath = Path.GetTempFileName();
116
+ try
117
+ {
118
+ File.WriteAllText(projectPath, projectContents);
119
+ var expectedTfms = new[] { expectedTfm1, expectedTfm2 }.Where(tfm => tfm is not null).ToArray();
120
+ var buildFile = ProjectBuildFile.Open(Path.GetDirectoryName(projectPath)!, projectPath);
121
+ var actualTfms = MSBuildHelper.GetTargetFrameworkMonikers(ImmutableArray.Create(buildFile));
122
+ Assert.Equal(expectedTfms, actualTfms);
123
+ }
124
+ finally
125
+ {
126
+ File.Delete(projectPath);
127
+ }
128
+ }
129
+
130
+ [Theory]
131
+ [MemberData(nameof(GetTopLevelPackageDependenyInfosTestData))]
132
+ public async Task TopLevelPackageDependenciesCanBeDetermined((string Path, string Content)[] buildFileContents, Dependency[] expectedTopLevelDependencies)
133
+ {
134
+ using var testDirectory = new TemporaryDirectory();
135
+ var buildFiles = new List<ProjectBuildFile>();
136
+ foreach (var (path, content) in buildFileContents)
137
+ {
138
+ var fullPath = Path.Combine(testDirectory.DirectoryPath, path);
139
+ await File.WriteAllTextAsync(fullPath, content);
140
+ buildFiles.Add(ProjectBuildFile.Parse(testDirectory.DirectoryPath, fullPath, content));
141
+ }
142
+
143
+ var actualTopLevelDependencies = MSBuildHelper.GetTopLevelPackageDependenyInfos(buildFiles.ToImmutableArray());
144
+ Assert.Equal(expectedTopLevelDependencies, actualTopLevelDependencies);
145
+ }
146
+
147
+ [Fact]
148
+ public async Task AllPackageDependenciesCanBeTraversed()
149
+ {
150
+ using var temp = new TemporaryDirectory();
151
+ var expectedDependencies = new Dependency[]
152
+ {
153
+ new("Microsoft.Bcl.AsyncInterfaces", "7.0.0", DependencyType.Unknown),
154
+ new("Microsoft.Extensions.DependencyInjection", "7.0.0", DependencyType.Unknown),
155
+ new("Microsoft.Extensions.DependencyInjection.Abstractions", "7.0.0", DependencyType.Unknown),
156
+ new("Microsoft.Extensions.Http", "7.0.0", DependencyType.Unknown),
157
+ new("Microsoft.Extensions.Logging", "7.0.0", DependencyType.Unknown),
158
+ new("Microsoft.Extensions.Logging.Abstractions", "7.0.0", DependencyType.Unknown),
159
+ new("Microsoft.Extensions.Options", "7.0.0", DependencyType.Unknown),
160
+ new("Microsoft.Extensions.Primitives", "7.0.0", DependencyType.Unknown),
161
+ new("System.Buffers", "4.5.1", DependencyType.Unknown),
162
+ new("System.ComponentModel.Annotations", "5.0.0", DependencyType.Unknown),
163
+ new("System.Diagnostics.DiagnosticSource", "7.0.0", DependencyType.Unknown),
164
+ new("System.Memory", "4.5.5", DependencyType.Unknown),
165
+ new("System.Numerics.Vectors", "4.4.0", DependencyType.Unknown),
166
+ new("System.Runtime.CompilerServices.Unsafe", "6.0.0", DependencyType.Unknown),
167
+ new("System.Threading.Tasks.Extensions", "4.5.4", DependencyType.Unknown),
168
+ new("NETStandard.Library", "2.0.3", DependencyType.Unknown),
169
+ };
170
+ var actualDependencies = await MSBuildHelper.GetAllPackageDependenciesAsync(temp.DirectoryPath, temp.DirectoryPath, "netstandard2.0", new[] { new Dependency("Microsoft.Extensions.Http", "7.0.0", DependencyType.Unknown) });
171
+ Assert.Equal(expectedDependencies, actualDependencies);
172
+ }
173
+
174
+ [Fact]
175
+ public async Task AllPackageDependencies_DoNotTruncateLongDependencyLists()
176
+ {
177
+ using var temp = new TemporaryDirectory();
178
+ var expectedDependencies = new Dependency[]
179
+ {
180
+ new("Castle.Core", "4.4.1", DependencyType.Unknown),
181
+ new("Microsoft.ApplicationInsights", "2.10.0", DependencyType.Unknown),
182
+ new("Microsoft.ApplicationInsights.Agent.Intercept", "2.4.0", DependencyType.Unknown),
183
+ new("Microsoft.ApplicationInsights.DependencyCollector", "2.10.0", DependencyType.Unknown),
184
+ new("Microsoft.ApplicationInsights.PerfCounterCollector", "2.10.0", DependencyType.Unknown),
185
+ new("Microsoft.ApplicationInsights.WindowsServer", "2.10.0", DependencyType.Unknown),
186
+ new("Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel", "2.10.0", DependencyType.Unknown),
187
+ new("Microsoft.AspNet.TelemetryCorrelation", "1.0.5", DependencyType.Unknown),
188
+ new("Microsoft.Bcl.AsyncInterfaces", "7.0.0", DependencyType.Unknown),
189
+ new("Microsoft.Extensions.Caching.Abstractions", "1.0.0", DependencyType.Unknown),
190
+ new("Microsoft.Extensions.Caching.Memory", "1.0.0", DependencyType.Unknown),
191
+ new("Microsoft.Extensions.DependencyInjection", "7.0.0", DependencyType.Unknown),
192
+ new("Microsoft.Extensions.DependencyInjection.Abstractions", "7.0.0", DependencyType.Unknown),
193
+ new("Microsoft.Extensions.DiagnosticAdapter", "1.1.0", DependencyType.Unknown),
194
+ new("Microsoft.Extensions.Http", "7.0.0", DependencyType.Unknown),
195
+ new("Microsoft.Extensions.Logging", "7.0.0", DependencyType.Unknown),
196
+ new("Microsoft.Extensions.Logging.Abstractions", "7.0.0", DependencyType.Unknown),
197
+ new("Microsoft.Extensions.Options", "7.0.0", DependencyType.Unknown),
198
+ new("Microsoft.Extensions.PlatformAbstractions", "1.1.0", DependencyType.Unknown),
199
+ new("Microsoft.Extensions.Primitives", "7.0.0", DependencyType.Unknown),
200
+ new("Moq", "4.16.1", DependencyType.Unknown),
201
+ new("MSTest.TestFramework", "2.1.0", DependencyType.Unknown),
202
+ new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown),
203
+ new("System", "4.1.311.2", DependencyType.Unknown),
204
+ new("System.Buffers", "4.5.1", DependencyType.Unknown),
205
+ new("System.Collections.Concurrent", "4.3.0", DependencyType.Unknown),
206
+ new("System.Collections.Immutable", "1.3.0", DependencyType.Unknown),
207
+ new("System.Collections.NonGeneric", "4.3.0", DependencyType.Unknown),
208
+ new("System.Collections.Specialized", "4.3.0", DependencyType.Unknown),
209
+ new("System.ComponentModel", "4.3.0", DependencyType.Unknown),
210
+ new("System.ComponentModel.Annotations", "5.0.0", DependencyType.Unknown),
211
+ new("System.ComponentModel.Primitives", "4.3.0", DependencyType.Unknown),
212
+ new("System.ComponentModel.TypeConverter", "4.3.0", DependencyType.Unknown),
213
+ new("System.Core", "3.5.21022.801", DependencyType.Unknown),
214
+ new("System.Data.Common", "4.3.0", DependencyType.Unknown),
215
+ new("System.Diagnostics.DiagnosticSource", "7.0.0", DependencyType.Unknown),
216
+ new("System.Diagnostics.PerformanceCounter", "4.5.0", DependencyType.Unknown),
217
+ new("System.Diagnostics.StackTrace", "4.3.0", DependencyType.Unknown),
218
+ new("System.Dynamic.Runtime", "4.3.0", DependencyType.Unknown),
219
+ new("System.IO.FileSystem.Primitives", "4.3.0", DependencyType.Unknown),
220
+ new("System.Linq", "4.3.0", DependencyType.Unknown),
221
+ new("System.Linq.Expressions", "4.3.0", DependencyType.Unknown),
222
+ new("System.Memory", "4.5.5", DependencyType.Unknown),
223
+ new("System.Net.WebHeaderCollection", "4.3.0", DependencyType.Unknown),
224
+ new("System.Numerics.Vectors", "4.4.0", DependencyType.Unknown),
225
+ new("System.ObjectModel", "4.3.0", DependencyType.Unknown),
226
+ new("System.Private.DataContractSerialization", "4.3.0", DependencyType.Unknown),
227
+ new("System.Reflection.Emit", "4.3.0", DependencyType.Unknown),
228
+ new("System.Reflection.Emit.ILGeneration", "4.3.0", DependencyType.Unknown),
229
+ new("System.Reflection.Emit.Lightweight", "4.3.0", DependencyType.Unknown),
230
+ new("System.Reflection.Metadata", "1.4.1", DependencyType.Unknown),
231
+ new("System.Reflection.TypeExtensions", "4.3.0", DependencyType.Unknown),
232
+ new("System.Runtime.CompilerServices.Unsafe", "6.0.0", DependencyType.Unknown),
233
+ new("System.Runtime.InteropServices.RuntimeInformation", "4.3.0", DependencyType.Unknown),
234
+ new("System.Runtime.Numerics", "4.3.0", DependencyType.Unknown),
235
+ new("System.Runtime.Serialization.Json", "4.3.0", DependencyType.Unknown),
236
+ new("System.Runtime.Serialization.Primitives", "4.3.0", DependencyType.Unknown),
237
+ new("System.Security.Claims", "4.3.0", DependencyType.Unknown),
238
+ new("System.Security.Cryptography.OpenSsl", "4.3.0", DependencyType.Unknown),
239
+ new("System.Security.Cryptography.Primitives", "4.3.0", DependencyType.Unknown),
240
+ new("System.Security.Principal", "4.3.0", DependencyType.Unknown),
241
+ new("System.Text.RegularExpressions", "4.3.0", DependencyType.Unknown),
242
+ new("System.Threading", "4.3.0", DependencyType.Unknown),
243
+ new("System.Threading.Tasks.Extensions", "4.5.4", DependencyType.Unknown),
244
+ new("System.Threading.Thread", "4.3.0", DependencyType.Unknown),
245
+ new("System.Threading.ThreadPool", "4.3.0", DependencyType.Unknown),
246
+ new("System.Xml.ReaderWriter", "4.3.0", DependencyType.Unknown),
247
+ new("System.Xml.XDocument", "4.3.0", DependencyType.Unknown),
248
+ new("System.Xml.XmlDocument", "4.3.0", DependencyType.Unknown),
249
+ new("System.Xml.XmlSerializer", "4.3.0", DependencyType.Unknown),
250
+ new("Microsoft.ApplicationInsights.Web", "2.10.0", DependencyType.Unknown),
251
+ new("MSTest.TestAdapter", "2.1.0", DependencyType.Unknown),
252
+ new("NETStandard.Library", "2.0.3", DependencyType.Unknown),
253
+ };
254
+ var packages = new[] {
255
+ new Dependency("System", "4.1.311.2", DependencyType.Unknown),
256
+ new Dependency("System.Core", "3.5.21022.801", DependencyType.Unknown),
257
+ new Dependency("Moq", "4.16.1", DependencyType.Unknown),
258
+ new Dependency("Castle.Core", "4.4.1", DependencyType.Unknown),
259
+ new Dependency("MSTest.TestAdapter", "2.1.0", DependencyType.Unknown),
260
+ new Dependency("MSTest.TestFramework", "2.1.0", DependencyType.Unknown),
261
+ new Dependency("Microsoft.ApplicationInsights", "2.10.0", DependencyType.Unknown),
262
+ new Dependency("Microsoft.ApplicationInsights.Agent.Intercept", "2.4.0", DependencyType.Unknown),
263
+ new Dependency("Microsoft.ApplicationInsights.DependencyCollector", "2.10.0", DependencyType.Unknown),
264
+ new Dependency("Microsoft.ApplicationInsights.PerfCounterCollector", "2.10.0", DependencyType.Unknown),
265
+ new Dependency("Microsoft.ApplicationInsights.Web", "2.10.0", DependencyType.Unknown),
266
+ new Dependency("Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel", "2.10.0", DependencyType.Unknown),
267
+ new Dependency("Microsoft.ApplicationInsights.WindowsServer", "2.10.0", DependencyType.Unknown),
268
+ new Dependency("Microsoft.Extensions.Http", "7.0.0", DependencyType.Unknown),
269
+ new Dependency("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
270
+ };
271
+ var actualDependencies = await MSBuildHelper.GetAllPackageDependenciesAsync(temp.DirectoryPath, temp.DirectoryPath, "netstandard2.0", packages);
272
+ for(int i = 0; i < actualDependencies.Length; i++)
273
+ {
274
+ var ad = actualDependencies[i];
275
+ var ed = expectedDependencies[i];
276
+ Assert.Equal(ed, ad);
277
+ }
278
+ Assert.Equal(expectedDependencies, actualDependencies);
279
+ }
280
+
281
+ [Fact]
282
+ public async Task AllPackageDependencies_DoNotIncludeUpdateOnlyPackages()
283
+ {
284
+ using var temp = new TemporaryDirectory();
285
+ var expectedDependencies = new Dependency[]
286
+ {
287
+ new("Microsoft.Bcl.AsyncInterfaces", "7.0.0", DependencyType.Unknown),
288
+ new("Microsoft.Extensions.DependencyInjection", "7.0.0", DependencyType.Unknown),
289
+ new("Microsoft.Extensions.DependencyInjection.Abstractions", "7.0.0", DependencyType.Unknown),
290
+ new("Microsoft.Extensions.Http", "7.0.0", DependencyType.Unknown),
291
+ new("Microsoft.Extensions.Logging", "7.0.0", DependencyType.Unknown),
292
+ new("Microsoft.Extensions.Logging.Abstractions", "7.0.0", DependencyType.Unknown),
293
+ new("Microsoft.Extensions.Options", "7.0.0", DependencyType.Unknown),
294
+ new("Microsoft.Extensions.Primitives", "7.0.0", DependencyType.Unknown),
295
+ new("System.Buffers", "4.5.1", DependencyType.Unknown),
296
+ new("System.ComponentModel.Annotations", "5.0.0", DependencyType.Unknown),
297
+ new("System.Diagnostics.DiagnosticSource", "7.0.0", DependencyType.Unknown),
298
+ new("System.Memory", "4.5.5", DependencyType.Unknown),
299
+ new("System.Numerics.Vectors", "4.4.0", DependencyType.Unknown),
300
+ new("System.Runtime.CompilerServices.Unsafe", "6.0.0", DependencyType.Unknown),
301
+ new("System.Threading.Tasks.Extensions", "4.5.4", DependencyType.Unknown),
302
+ new("NETStandard.Library", "2.0.3", DependencyType.Unknown),
303
+ };
304
+ var packages = new[] {
305
+ new Dependency("Microsoft.Extensions.Http", "7.0.0", DependencyType.Unknown),
306
+ new Dependency("Newtonsoft.Json", "12.0.1", DependencyType.Unknown, IsUpdate: true)
307
+ };
308
+ var actualDependencies = await MSBuildHelper.GetAllPackageDependenciesAsync(temp.DirectoryPath, temp.DirectoryPath, "netstandard2.0", packages);
309
+ Assert.Equal(expectedDependencies, actualDependencies);
310
+ }
311
+
312
+ [Fact]
313
+ public async Task AllPackageDependenciesCanBeFoundWithNuGetConfig()
314
+ {
315
+ var nugetPackagesDirectory = Environment.GetEnvironmentVariable("NUGET_PACKAGES");
316
+ var nugetHttpCacheDirectory = Environment.GetEnvironmentVariable("NUGET_HTTP_CACHE_PATH");
317
+
318
+ try
319
+ {
320
+ using var temp = new TemporaryDirectory();
321
+
322
+ // It is important to have empty NuGet caches for this test, so override them with temp directories.
323
+ var tempNuGetPackagesDirectory = Path.Combine(temp.DirectoryPath, ".nuget", "packages");
324
+ Environment.SetEnvironmentVariable("NUGET_PACKAGES", tempNuGetPackagesDirectory);
325
+ var tempNuGetHttpCacheDirectory = Path.Combine(temp.DirectoryPath, ".nuget", "v3-cache");
326
+ Environment.SetEnvironmentVariable("NUGET_HTTP_CACHE_PATH", tempNuGetHttpCacheDirectory);
327
+
328
+ // First validate that we are unable to find dependencies for the package version without a NuGet.config.
329
+ var dependenciesNoNuGetConfig = await MSBuildHelper.GetAllPackageDependenciesAsync(temp.DirectoryPath, temp.DirectoryPath, "netstandard2.0", new[] { new Dependency("Microsoft.CodeAnalysis.Common", "4.8.0-3.23457.5", DependencyType.Unknown) });
330
+ Assert.Equal(Array.Empty<Dependency>(), dependenciesNoNuGetConfig);
331
+
332
+ // Write the NuGet.config and try again.
333
+ await File.WriteAllTextAsync(Path.Combine(temp.DirectoryPath, "NuGet.Config"), """
334
+ <?xml version="1.0" encoding="utf-8"?>
335
+ <configuration>
336
+ <packageSources>
337
+ <clear />
338
+ <add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
339
+ <add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
340
+ </packageSources>
341
+ </configuration>
342
+ """);
343
+
344
+ var expectedDependencies = new Dependency[]
345
+ {
346
+ new("Microsoft.CodeAnalysis.Common", "4.8.0-3.23457.5", DependencyType.Unknown),
347
+ new("System.Buffers", "4.5.1", DependencyType.Unknown),
348
+ new("System.Collections.Immutable", "7.0.0", DependencyType.Unknown),
349
+ new("System.Memory", "4.5.5", DependencyType.Unknown),
350
+ new("System.Numerics.Vectors", "4.4.0", DependencyType.Unknown),
351
+ new("System.Reflection.Metadata", "7.0.0", DependencyType.Unknown),
352
+ new("System.Runtime.CompilerServices.Unsafe", "6.0.0", DependencyType.Unknown),
353
+ new("System.Text.Encoding.CodePages", "7.0.0", DependencyType.Unknown),
354
+ new("System.Threading.Tasks.Extensions", "4.5.4", DependencyType.Unknown),
355
+ new("Microsoft.CodeAnalysis.Analyzers", "3.3.4", DependencyType.Unknown),
356
+ new("NETStandard.Library", "2.0.3", DependencyType.Unknown),
357
+ };
358
+ var actualDependencies = await MSBuildHelper.GetAllPackageDependenciesAsync(temp.DirectoryPath, temp.DirectoryPath, "netstandard2.0", new[] { new Dependency("Microsoft.CodeAnalysis.Common", "4.8.0-3.23457.5", DependencyType.Unknown) });
359
+ Assert.Equal(expectedDependencies, actualDependencies);
360
+ }
361
+ finally
362
+ {
363
+ // Restore the NuGet caches.
364
+ Environment.SetEnvironmentVariable("NUGET_PACKAGES", nugetPackagesDirectory);
365
+ Environment.SetEnvironmentVariable("NUGET_HTTP_CACHE_PATH", nugetHttpCacheDirectory);
366
+ }
367
+ }
368
+
369
+ public static IEnumerable<object[]> GetTopLevelPackageDependenyInfosTestData()
370
+ {
371
+ // simple case
372
+ yield return new object[]
373
+ {
374
+ // build file contents
375
+ new[]
376
+ {
377
+ ("project.csproj", """
378
+ <Project Sdk="Microsoft.NET.Sdk">
379
+ <ItemGroup>
380
+ <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
381
+ </ItemGroup>
382
+ </Project>
383
+ """)
384
+ },
385
+ // expected dependencies
386
+ new Dependency[]
387
+ {
388
+ new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
389
+ }
390
+ };
391
+
392
+ // version is a child-node of the package reference
393
+ yield return new object[]
394
+ {
395
+ // build file contents
396
+ new[]
397
+ {
398
+ ("project.csproj", """
399
+ <Project Sdk="Microsoft.NET.Sdk">
400
+ <ItemGroup>
401
+ <PackageReference Include="Newtonsoft.Json">
402
+ <Version>12.0.1</Version>
403
+ </PackageReference>
404
+ </ItemGroup>
405
+ </Project>
406
+ """)
407
+ },
408
+ // expected dependencies
409
+ new Dependency[]
410
+ {
411
+ new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
412
+ }
413
+ };
414
+
415
+ // version is in property in same file
416
+ yield return new object[]
417
+ {
418
+ // build file contents
419
+ new[]
420
+ {
421
+ ("project.csproj", """
422
+ <Project Sdk="Microsoft.NET.Sdk">
423
+ <PropertyGroup>
424
+ <NewtonsoftJsonVersion>12.0.1</NewtonsoftJsonVersion>
425
+ </PropertyGroup>
426
+ <ItemGroup>
427
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
428
+ </ItemGroup>
429
+ </Project>
430
+ """)
431
+ },
432
+ // expected dependencies
433
+ new Dependency[]
434
+ {
435
+ new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
436
+ }
437
+ };
438
+
439
+ // version is a property not triggered by a condition
440
+ yield return new object[]
441
+ {
442
+ // build file contents
443
+ new[]
444
+ {
445
+ ("project.csproj", """
446
+ <Project Sdk="Microsoft.NET.Sdk">
447
+ <PropertyGroup>
448
+ <TargetFramework>netstandard2.0</TargetFramework>
449
+ <NewtonsoftJsonVersion>12.0.1</NewtonsoftJsonVersion>
450
+ <NewtonsoftJsonVersion Condition="$(PropertyThatDoesNotExist) == 'true'">13.0.1</NewtonsoftJsonVersion>
451
+ </PropertyGroup>
452
+ <ItemGroup>
453
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
454
+ </ItemGroup>
455
+ </Project>
456
+ """)
457
+ },
458
+ // expected dependencies
459
+ new Dependency[]
460
+ {
461
+ new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
462
+ }
463
+ };
464
+
465
+ // version is a property with a condition checking for an empty string
466
+ yield return new object[]
467
+ {
468
+ // build file contents
469
+ new[]
470
+ {
471
+ ("project.csproj", """
472
+ <Project Sdk="Microsoft.NET.Sdk">
473
+ <PropertyGroup>
474
+ <TargetFramework>netstandard2.0</TargetFramework>
475
+ <NewtonsoftJsonVersion Condition="$(NewtonsoftJsonVersion) == ''">12.0.1</NewtonsoftJsonVersion>
476
+ <NewtonsoftJsonVersion Condition="$(PropertyThatDoesNotExist) == 'true'">13.0.1</NewtonsoftJsonVersion>
477
+ </PropertyGroup>
478
+ <ItemGroup>
479
+ <PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
480
+ </ItemGroup>
481
+ </Project>
482
+ """)
483
+ },
484
+ // expected dependencies
485
+ new Dependency[]
486
+ {
487
+ new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
488
+ }
489
+ };
490
+
491
+ // version is set in one file, used in another
492
+ yield return new object[]
493
+ {
494
+ // build file contents
495
+ new[]
496
+ {
497
+ ("Packages.props", """
498
+ <Project>
499
+ <ItemGroup>
500
+ <PackageReference Update="Azure.Identity" Version="1.6.0" />
501
+ <PackageReference Update="Microsoft.Data.SqlClient" Version="5.1.4" />
502
+ </ItemGroup>
503
+ </Project>
504
+ """),
505
+ ("project.csproj", """
506
+ <Project Sdk="Microsoft.NET.Sdk">
507
+ <PropertyGroup>
508
+ <TargetFramework>netstandard2.0</TargetFramework>
509
+ </PropertyGroup>
510
+ <ItemGroup>
511
+ <PackageReference Include="Azure.Identity" Version="1.6.1" />
512
+ </ItemGroup>
513
+ </Project>
514
+ """)
515
+ },
516
+ // expected dependencies
517
+ new Dependency[]
518
+ {
519
+ new("Azure.Identity", "1.6.0", DependencyType.Unknown),
520
+ new("Microsoft.Data.SqlClient", "5.1.4", DependencyType.Unknown, IsUpdate: true)
521
+ }
522
+ };
523
+
524
+ // version is set in one file, used in another
525
+ yield return new object[]
526
+ {
527
+ // build file contents
528
+ new[]
529
+ {
530
+ ("project.csproj", """
531
+ <Project Sdk="Microsoft.NET.Sdk">
532
+ <PropertyGroup>
533
+ <TargetFramework>netstandard2.0</TargetFramework>
534
+ </PropertyGroup>
535
+ <ItemGroup>
536
+ <PackageReference Include="Azure.Identity" />
537
+ </ItemGroup>
538
+ </Project>
539
+ """),
540
+ ("Packages.props", """
541
+ <Project>
542
+ <ItemGroup>
543
+ <PackageReference Update="Azure.Identity" Version="1.6.0" />
544
+ <PackageReference Update="Microsoft.Data.SqlClient" Version="5.1.4" />
545
+ </ItemGroup>
546
+ </Project>
547
+ """)
548
+ },
549
+ // expected dependencies
550
+ new Dependency[]
551
+ {
552
+ new("Azure.Identity", "1.6.0", DependencyType.Unknown),
553
+ new("Microsoft.Data.SqlClient", "5.1.4", DependencyType.Unknown, IsUpdate: true)
554
+ }
555
+ };
556
+ }
557
+
558
+ public static IEnumerable<object[]> SolutionProjectPathTestData()
559
+ {
560
+ yield return new object[]
561
+ {
562
+ """
563
+ Microsoft Visual Studio Solution File, Format Version 12.00
564
+ # Visual Studio 14
565
+ VisualStudioVersion = 14.0.22705.0
566
+ MinimumVisualStudioVersion = 10.0.40219.1
567
+ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Some.Project", "src\Some.Project\SomeProject.csproj", "{782E0C0A-10D3-444D-9640-263D03D2B20C}"
568
+ EndProject
569
+ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Some.Project.Test", "src\Some.Project.Test\Some.Project.Test.csproj", "{5C15FD5B-1975-4CEA-8F1B-C0C9174C60A9}"
570
+ EndProject
571
+ Global
572
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
573
+ Debug|Any CPU = Debug|Any CPU
574
+ Release|Any CPU = Release|Any CPU
575
+ EndGlobalSection
576
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
577
+ {782E0C0A-10D3-444D-9640-263D03D2B20C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
578
+ {782E0C0A-10D3-444D-9640-263D03D2B20C}.Debug|Any CPU.Build.0 = Debug|Any CPU
579
+ {782E0C0A-10D3-444D-9640-263D03D2B20C}.Release|Any CPU.ActiveCfg = Release|Any CPU
580
+ {782E0C0A-10D3-444D-9640-263D03D2B20C}.Release|Any CPU.Build.0 = Release|Any CPU
581
+ {5C15FD5B-1975-4CEA-8F1B-C0C9174C60A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
582
+ {5C15FD5B-1975-4CEA-8F1B-C0C9174C60A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
583
+ {5C15FD5B-1975-4CEA-8F1B-C0C9174C60A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
584
+ {5C15FD5B-1975-4CEA-8F1B-C0C9174C60A9}.Release|Any CPU.Build.0 = Release|Any CPU
585
+ EndGlobalSection
586
+ GlobalSection(SolutionProperties) = preSolution
587
+ HideSolutionNode = FALSE
588
+ EndGlobalSection
589
+ EndGlobal
590
+ """,
591
+ new[]
592
+ {
593
+ "src/Some.Project/SomeProject.csproj",
594
+ "src/Some.Project.Test/Some.Project.Test.csproj",
595
+ },
596
+ };
597
+ }
598
+ }