dependabot-nuget 0.240.0 → 0.241.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/helpers/build +45 -0
- data/helpers/lib/NuGetUpdater/.editorconfig +364 -0
- data/helpers/lib/NuGetUpdater/.gitignore +5 -0
- data/helpers/lib/NuGetUpdater/Directory.Build.props +10 -0
- data/helpers/lib/NuGetUpdater/Directory.Common.props +16 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Build.props +14 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Build.targets +7 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Packages.props +29 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Build.Tasks/NuGet.Build.Tasks.csproj +27 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/AssemblyMetadataExtractor.cs +203 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/NuGet.CommandLine.csproj +33 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Commands/NuGet.Commands.csproj +26 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Common/NuGet.Common.csproj +21 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Config +6 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Configuration/NuGet.Configuration.csproj +24 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Credentials/NuGet.Credentials.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.DependencyResolver.Core/NuGet.DependencyResolver.Core.csproj +22 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Frameworks/NuGet.Frameworks.csproj +17 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.LibraryModel/NuGet.LibraryModel.csproj +17 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.PackageManagement/NuGet.PackageManagement.csproj +27 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Packaging/NuGet.Packaging.csproj +28 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.ProjectModel/NuGet.ProjectModel.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Protocol/NuGet.Protocol.csproj +21 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Resolver/NuGet.Resolver.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Versioning/NuGet.Versioning.csproj +17 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/README.md +1 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/FrameworkCheckCommand.cs +35 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +43 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/NuGetUpdater.Cli.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +31 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.FrameworkCheck.cs +42 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +323 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/NuGetUpdater.Cli.Test.csproj +24 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Dependency.cs +3 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyType.cs +12 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/BuildFile.cs +97 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/DotNetToolsJsonBuildFile.cs +24 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +25 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +32 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/PackagesConfigBuildFile.cs +31 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/ProjectBuildFile.cs +94 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/XmlBuildFile.cs +14 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/CompatabilityChecker.cs +39 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/FrameworkCompatibilityService.cs +73 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/SupportedFrameworks.cs +146 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/NuGetUpdater.Core.csproj +27 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs +316 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectResolver.cs +87 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/ConfigurationFile.cs +3 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +66 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +48 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +172 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SdkPackageUpdater.cs +498 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateResult.cs +7 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +105 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/JsonHelper.cs +222 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/Logger.cs +24 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +443 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/NuGetHelper.cs +15 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +69 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProcessExtensions.cs +66 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/XmlExtensions.cs +124 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/DotNetToolsJsonBuildFileTests.cs +52 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +63 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/PackagesConfigBuildFileTests.cs +63 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/ProjectBuildFileTests.cs +154 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/CompatibilityCheckerFacts.cs +64 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/FrameworkCompatibilityServiceFacts.cs +122 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/SupportedFrameworkFacts.cs +68 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/NuGetUpdater.Core.Test.csproj +23 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TemporaryDirectory.cs +36 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestExtensions.cs +15 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +79 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorker.DirsProj.cs +201 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +147 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DotNetTools.cs +225 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +217 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Mixed.cs +94 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +938 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Sdk.cs +2177 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/JsonHelperTests.cs +239 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +394 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterHelperTests.cs +179 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterTests.cs +238 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.sln +152 -0
- data/helpers/lib/NuGetUpdater/xunit.runner.json +4 -0
- data/lib/dependabot/nuget/metadata_finder.rb +4 -4
- metadata +91 -5
@@ -0,0 +1,239 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using NuGetUpdater.Core.Utilities;
|
4
|
+
using Xunit;
|
5
|
+
|
6
|
+
namespace NuGetUpdater.Core.Test.Utilities;
|
7
|
+
|
8
|
+
public class JsonHelperTests
|
9
|
+
{
|
10
|
+
[Theory]
|
11
|
+
[MemberData(nameof(JsonUpdaterTestData))]
|
12
|
+
public void UpdateJsonPreservingComments(string json, string[] propertyPath, string newValue, string expectedJson)
|
13
|
+
{
|
14
|
+
var updatedJson = JsonHelper.UpdateJsonProperty(json, propertyPath, newValue, StringComparison.OrdinalIgnoreCase).Replace("\r", string.Empty);
|
15
|
+
expectedJson = expectedJson.Replace("\r", string.Empty);
|
16
|
+
Assert.Equal(expectedJson, updatedJson);
|
17
|
+
}
|
18
|
+
|
19
|
+
public static IEnumerable<object[]> JsonUpdaterTestData()
|
20
|
+
{
|
21
|
+
yield return new object[]
|
22
|
+
{
|
23
|
+
// json
|
24
|
+
"""
|
25
|
+
{
|
26
|
+
// this is a comment
|
27
|
+
"version": 1,
|
28
|
+
"isRoot": true,
|
29
|
+
"tools": {
|
30
|
+
"microsoft.botsay": {
|
31
|
+
// this is a deep comment
|
32
|
+
"version": "1.0.0",
|
33
|
+
"commands": [
|
34
|
+
"botsay"
|
35
|
+
]
|
36
|
+
},
|
37
|
+
"dotnetsay": {
|
38
|
+
"version": "2.1.3",
|
39
|
+
"commands": [ // end of line comment
|
40
|
+
"dotnetsay"
|
41
|
+
]
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
""",
|
46
|
+
// property path
|
47
|
+
new[]
|
48
|
+
{
|
49
|
+
"tools",
|
50
|
+
"microsoft.botsay",
|
51
|
+
"version"
|
52
|
+
},
|
53
|
+
// new value
|
54
|
+
"1.1.0",
|
55
|
+
// expected json
|
56
|
+
"""
|
57
|
+
{
|
58
|
+
// this is a comment
|
59
|
+
"version": 1,
|
60
|
+
"isRoot": true,
|
61
|
+
"tools": {
|
62
|
+
"microsoft.botsay": {
|
63
|
+
// this is a deep comment
|
64
|
+
"version": "1.1.0",
|
65
|
+
"commands": [
|
66
|
+
"botsay"
|
67
|
+
]
|
68
|
+
},
|
69
|
+
"dotnetsay": {
|
70
|
+
"version": "2.1.3",
|
71
|
+
"commands": [ // end of line comment
|
72
|
+
"dotnetsay"
|
73
|
+
]
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
"""
|
78
|
+
};
|
79
|
+
|
80
|
+
yield return new object[]
|
81
|
+
{
|
82
|
+
// json
|
83
|
+
"""
|
84
|
+
{
|
85
|
+
// Defines version of MSBuild project SDKs to use
|
86
|
+
// https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2017#how-project-sdks-are-resolved
|
87
|
+
// https://docs.microsoft.com/en-us/dotnet/core/tools/global-json#globaljson-schema
|
88
|
+
"msbuild-sdks": {
|
89
|
+
"Microsoft.Build.Traversal": "4.1.0",
|
90
|
+
"Microsoft.Build.NoTargets": "3.6.0"
|
91
|
+
},
|
92
|
+
"sdk": {
|
93
|
+
"version": "6.0.400",
|
94
|
+
"rollForward": "latestMajor"
|
95
|
+
}
|
96
|
+
}
|
97
|
+
""",
|
98
|
+
// property path
|
99
|
+
new[]
|
100
|
+
{
|
101
|
+
"msbuild-sdks",
|
102
|
+
"Microsoft.Build.NoTargets"
|
103
|
+
},
|
104
|
+
// new value
|
105
|
+
"3.7.0",
|
106
|
+
// expected json
|
107
|
+
"""
|
108
|
+
{
|
109
|
+
// Defines version of MSBuild project SDKs to use
|
110
|
+
// https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2017#how-project-sdks-are-resolved
|
111
|
+
// https://docs.microsoft.com/en-us/dotnet/core/tools/global-json#globaljson-schema
|
112
|
+
"msbuild-sdks": {
|
113
|
+
"Microsoft.Build.Traversal": "4.1.0",
|
114
|
+
"Microsoft.Build.NoTargets": "3.7.0"
|
115
|
+
},
|
116
|
+
"sdk": {
|
117
|
+
"version": "6.0.400",
|
118
|
+
"rollForward": "latestMajor"
|
119
|
+
}
|
120
|
+
}
|
121
|
+
"""
|
122
|
+
};
|
123
|
+
|
124
|
+
// differing case between `propertyPath` and the actual property values
|
125
|
+
yield return new object[]
|
126
|
+
{
|
127
|
+
// json
|
128
|
+
"""
|
129
|
+
{
|
130
|
+
"version": 1,
|
131
|
+
"isRoot": true,
|
132
|
+
"tools": {
|
133
|
+
"microsoft.botsay": {
|
134
|
+
// some comment
|
135
|
+
"version": "1.0.0",
|
136
|
+
"commands": [
|
137
|
+
"botsay"
|
138
|
+
]
|
139
|
+
},
|
140
|
+
"dotnetsay": {
|
141
|
+
"version": "2.1.3",
|
142
|
+
"commands": [
|
143
|
+
"dotnetsay"
|
144
|
+
]
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|
148
|
+
""",
|
149
|
+
// property path
|
150
|
+
new[]
|
151
|
+
{
|
152
|
+
"tools",
|
153
|
+
"Microsoft.BotSay",
|
154
|
+
"version"
|
155
|
+
},
|
156
|
+
// new value
|
157
|
+
"1.1.0",
|
158
|
+
// expected json
|
159
|
+
"""
|
160
|
+
{
|
161
|
+
"version": 1,
|
162
|
+
"isRoot": true,
|
163
|
+
"tools": {
|
164
|
+
"microsoft.botsay": {
|
165
|
+
// some comment
|
166
|
+
"version": "1.1.0",
|
167
|
+
"commands": [
|
168
|
+
"botsay"
|
169
|
+
]
|
170
|
+
},
|
171
|
+
"dotnetsay": {
|
172
|
+
"version": "2.1.3",
|
173
|
+
"commands": [
|
174
|
+
"dotnetsay"
|
175
|
+
]
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}
|
179
|
+
"""
|
180
|
+
};
|
181
|
+
|
182
|
+
// shallow property path
|
183
|
+
yield return new object[]
|
184
|
+
{
|
185
|
+
// original json
|
186
|
+
"""
|
187
|
+
{
|
188
|
+
"path1": {
|
189
|
+
"subpath1": "value1",
|
190
|
+
"subpath2": "value2"
|
191
|
+
},
|
192
|
+
"path2": "old-value"
|
193
|
+
}
|
194
|
+
""",
|
195
|
+
// property path
|
196
|
+
new[]
|
197
|
+
{
|
198
|
+
"path2"
|
199
|
+
},
|
200
|
+
// new value
|
201
|
+
"new-value",
|
202
|
+
// expected json
|
203
|
+
"""
|
204
|
+
{
|
205
|
+
"path1": {
|
206
|
+
"subpath1": "value1",
|
207
|
+
"subpath2": "value2"
|
208
|
+
},
|
209
|
+
"path2": "new-value"
|
210
|
+
}
|
211
|
+
"""
|
212
|
+
};
|
213
|
+
|
214
|
+
// line comment after comma
|
215
|
+
yield return new object[]
|
216
|
+
{
|
217
|
+
// original json
|
218
|
+
"""
|
219
|
+
{
|
220
|
+
"property1": "value1",
|
221
|
+
// some comment
|
222
|
+
"property2": "value2"
|
223
|
+
}
|
224
|
+
""",
|
225
|
+
// property path
|
226
|
+
new[] { "property2" },
|
227
|
+
// new value
|
228
|
+
"updated-value",
|
229
|
+
// expected json
|
230
|
+
"""
|
231
|
+
{
|
232
|
+
"property1": "value1",
|
233
|
+
// some comment
|
234
|
+
"property2": "updated-value"
|
235
|
+
}
|
236
|
+
"""
|
237
|
+
};
|
238
|
+
}
|
239
|
+
}
|
@@ -0,0 +1,394 @@
|
|
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 AllPackageDependenciesCanBeFoundWithNuGetConfig()
|
176
|
+
{
|
177
|
+
var nugetPackagesDirectory = Environment.GetEnvironmentVariable("NUGET_PACKAGES");
|
178
|
+
var nugetHttpCacheDirectory = Environment.GetEnvironmentVariable("NUGET_HTTP_CACHE_PATH");
|
179
|
+
|
180
|
+
try
|
181
|
+
{
|
182
|
+
using var temp = new TemporaryDirectory();
|
183
|
+
|
184
|
+
// It is important to have empty NuGet caches for this test, so override them with temp directories.
|
185
|
+
var tempNuGetPackagesDirectory = Path.Combine(temp.DirectoryPath, ".nuget", "packages");
|
186
|
+
Environment.SetEnvironmentVariable("NUGET_PACKAGES", tempNuGetPackagesDirectory);
|
187
|
+
var tempNuGetHttpCacheDirectory = Path.Combine(temp.DirectoryPath, ".nuget", "v3-cache");
|
188
|
+
Environment.SetEnvironmentVariable("NUGET_HTTP_CACHE_PATH", tempNuGetHttpCacheDirectory);
|
189
|
+
|
190
|
+
// First validate that we are unable to find dependencies for the package version without a NuGet.config.
|
191
|
+
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) });
|
192
|
+
Assert.Equal(Array.Empty<Dependency>(), dependenciesNoNuGetConfig);
|
193
|
+
|
194
|
+
// Write the NuGet.config and try again.
|
195
|
+
await File.WriteAllTextAsync(Path.Combine(temp.DirectoryPath, "NuGet.Config"), """
|
196
|
+
<?xml version="1.0" encoding="utf-8"?>
|
197
|
+
<configuration>
|
198
|
+
<packageSources>
|
199
|
+
<clear />
|
200
|
+
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
|
201
|
+
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
|
202
|
+
</packageSources>
|
203
|
+
</configuration>
|
204
|
+
""");
|
205
|
+
|
206
|
+
var expectedDependencies = new Dependency[]
|
207
|
+
{
|
208
|
+
new("Microsoft.CodeAnalysis.Common", "4.8.0-3.23457.5", DependencyType.Unknown),
|
209
|
+
new("System.Buffers", "4.5.1", DependencyType.Unknown),
|
210
|
+
new("System.Collections.Immutable", "7.0.0", DependencyType.Unknown),
|
211
|
+
new("System.Memory", "4.5.5", DependencyType.Unknown),
|
212
|
+
new("System.Numerics.Vectors", "4.4.0", DependencyType.Unknown),
|
213
|
+
new("System.Reflection.Metadata", "7.0.0", DependencyType.Unknown),
|
214
|
+
new("System.Runtime.CompilerServices.Unsafe", "6.0.0", DependencyType.Unknown),
|
215
|
+
new("System.Text.Encoding.CodePages", "7.0.0", DependencyType.Unknown),
|
216
|
+
new("System.Threading.Tasks.Extensions", "4.5.4", DependencyType.Unknown),
|
217
|
+
new("Microsoft.CodeAnalysis.Analyzers", "3.3.4", DependencyType.Unknown),
|
218
|
+
new("NETStandard.Library", "2.0.3", DependencyType.Unknown),
|
219
|
+
};
|
220
|
+
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) });
|
221
|
+
Assert.Equal(expectedDependencies, actualDependencies);
|
222
|
+
}
|
223
|
+
finally
|
224
|
+
{
|
225
|
+
// Restore the NuGet caches.
|
226
|
+
Environment.SetEnvironmentVariable("NUGET_PACKAGES", nugetPackagesDirectory);
|
227
|
+
Environment.SetEnvironmentVariable("NUGET_HTTP_CACHE_PATH", nugetHttpCacheDirectory);
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
public static IEnumerable<object[]> GetTopLevelPackageDependenyInfosTestData()
|
232
|
+
{
|
233
|
+
// simple case
|
234
|
+
yield return new object[]
|
235
|
+
{
|
236
|
+
// build file contents
|
237
|
+
new[]
|
238
|
+
{
|
239
|
+
("project.csproj", """
|
240
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
241
|
+
<ItemGroup>
|
242
|
+
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
243
|
+
</ItemGroup>
|
244
|
+
</Project>
|
245
|
+
""")
|
246
|
+
},
|
247
|
+
// expected dependencies
|
248
|
+
new Dependency[]
|
249
|
+
{
|
250
|
+
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
|
251
|
+
}
|
252
|
+
};
|
253
|
+
|
254
|
+
// version is a child-node of the package reference
|
255
|
+
yield return new object[]
|
256
|
+
{
|
257
|
+
// build file contents
|
258
|
+
new[]
|
259
|
+
{
|
260
|
+
("project.csproj", """
|
261
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
262
|
+
<ItemGroup>
|
263
|
+
<PackageReference Include="Newtonsoft.Json">
|
264
|
+
<Version>12.0.1</Version>
|
265
|
+
</PackageReference>
|
266
|
+
</ItemGroup>
|
267
|
+
</Project>
|
268
|
+
""")
|
269
|
+
},
|
270
|
+
// expected dependencies
|
271
|
+
new Dependency[]
|
272
|
+
{
|
273
|
+
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
|
274
|
+
}
|
275
|
+
};
|
276
|
+
|
277
|
+
// version is in property in same file
|
278
|
+
yield return new object[]
|
279
|
+
{
|
280
|
+
// build file contents
|
281
|
+
new[]
|
282
|
+
{
|
283
|
+
("project.csproj", """
|
284
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
285
|
+
<PropertyGroup>
|
286
|
+
<NewtonsoftJsonVersion>12.0.1</NewtonsoftJsonVersion>
|
287
|
+
</PropertyGroup>
|
288
|
+
<ItemGroup>
|
289
|
+
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
|
290
|
+
</ItemGroup>
|
291
|
+
</Project>
|
292
|
+
""")
|
293
|
+
},
|
294
|
+
// expected dependencies
|
295
|
+
new Dependency[]
|
296
|
+
{
|
297
|
+
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
|
298
|
+
}
|
299
|
+
};
|
300
|
+
|
301
|
+
// version is a property not triggered by a condition
|
302
|
+
yield return new object[]
|
303
|
+
{
|
304
|
+
// build file contents
|
305
|
+
new[]
|
306
|
+
{
|
307
|
+
("project.csproj", """
|
308
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
309
|
+
<PropertyGroup>
|
310
|
+
<TargetFramework>netstandard2.0</TargetFramework>
|
311
|
+
<NewtonsoftJsonVersion>12.0.1</NewtonsoftJsonVersion>
|
312
|
+
<NewtonsoftJsonVersion Condition="$(PropertyThatDoesNotExist) == 'true'">13.0.1</NewtonsoftJsonVersion>
|
313
|
+
</PropertyGroup>
|
314
|
+
<ItemGroup>
|
315
|
+
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
|
316
|
+
</ItemGroup>
|
317
|
+
</Project>
|
318
|
+
""")
|
319
|
+
},
|
320
|
+
// expected dependencies
|
321
|
+
new Dependency[]
|
322
|
+
{
|
323
|
+
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
|
324
|
+
}
|
325
|
+
};
|
326
|
+
|
327
|
+
// version is a property with a condition checking for an empty string
|
328
|
+
yield return new object[]
|
329
|
+
{
|
330
|
+
// build file contents
|
331
|
+
new[]
|
332
|
+
{
|
333
|
+
("project.csproj", """
|
334
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
335
|
+
<PropertyGroup>
|
336
|
+
<TargetFramework>netstandard2.0</TargetFramework>
|
337
|
+
<NewtonsoftJsonVersion Condition="$(NewtonsoftJsonVersion) == ''">12.0.1</NewtonsoftJsonVersion>
|
338
|
+
<NewtonsoftJsonVersion Condition="$(PropertyThatDoesNotExist) == 'true'">13.0.1</NewtonsoftJsonVersion>
|
339
|
+
</PropertyGroup>
|
340
|
+
<ItemGroup>
|
341
|
+
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
|
342
|
+
</ItemGroup>
|
343
|
+
</Project>
|
344
|
+
""")
|
345
|
+
},
|
346
|
+
// expected dependencies
|
347
|
+
new Dependency[]
|
348
|
+
{
|
349
|
+
new("Newtonsoft.Json", "12.0.1", DependencyType.Unknown)
|
350
|
+
}
|
351
|
+
};
|
352
|
+
}
|
353
|
+
|
354
|
+
public static IEnumerable<object[]> SolutionProjectPathTestData()
|
355
|
+
{
|
356
|
+
yield return new object[]
|
357
|
+
{
|
358
|
+
"""
|
359
|
+
Microsoft Visual Studio Solution File, Format Version 12.00
|
360
|
+
# Visual Studio 14
|
361
|
+
VisualStudioVersion = 14.0.22705.0
|
362
|
+
MinimumVisualStudioVersion = 10.0.40219.1
|
363
|
+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Some.Project", "src\Some.Project\SomeProject.csproj", "{782E0C0A-10D3-444D-9640-263D03D2B20C}"
|
364
|
+
EndProject
|
365
|
+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Some.Project.Test", "src\Some.Project.Test\Some.Project.Test.csproj", "{5C15FD5B-1975-4CEA-8F1B-C0C9174C60A9}"
|
366
|
+
EndProject
|
367
|
+
Global
|
368
|
+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
369
|
+
Debug|Any CPU = Debug|Any CPU
|
370
|
+
Release|Any CPU = Release|Any CPU
|
371
|
+
EndGlobalSection
|
372
|
+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
373
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
374
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
375
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
376
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Release|Any CPU.Build.0 = Release|Any CPU
|
377
|
+
{5C15FD5B-1975-4CEA-8F1B-C0C9174C60A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
378
|
+
{5C15FD5B-1975-4CEA-8F1B-C0C9174C60A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
379
|
+
{5C15FD5B-1975-4CEA-8F1B-C0C9174C60A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
380
|
+
{5C15FD5B-1975-4CEA-8F1B-C0C9174C60A9}.Release|Any CPU.Build.0 = Release|Any CPU
|
381
|
+
EndGlobalSection
|
382
|
+
GlobalSection(SolutionProperties) = preSolution
|
383
|
+
HideSolutionNode = FALSE
|
384
|
+
EndGlobalSection
|
385
|
+
EndGlobal
|
386
|
+
""",
|
387
|
+
new[]
|
388
|
+
{
|
389
|
+
"src/Some.Project/SomeProject.csproj",
|
390
|
+
"src/Some.Project.Test/Some.Project.Test.csproj",
|
391
|
+
},
|
392
|
+
};
|
393
|
+
}
|
394
|
+
}
|