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.
- 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 +23 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +36 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +47 -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 +460 -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 +83 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/XmlExtensions.cs +124 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/DotNetToolsJsonBuildFileTests.cs +53 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +80 -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 +598 -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,31 @@
|
|
1
|
+
using System;
|
2
|
+
using System.CommandLine;
|
3
|
+
using System.Threading.Tasks;
|
4
|
+
|
5
|
+
using NuGetUpdater.Cli.Commands;
|
6
|
+
|
7
|
+
namespace NuGetUpdater.Cli;
|
8
|
+
|
9
|
+
internal sealed class Program
|
10
|
+
{
|
11
|
+
internal static async Task<int> Main(string[] args)
|
12
|
+
{
|
13
|
+
var exitCode = 0;
|
14
|
+
Action<int> setExitCode = (int code) => exitCode = code;
|
15
|
+
|
16
|
+
var command = new RootCommand()
|
17
|
+
{
|
18
|
+
FrameworkCheckCommand.GetCommand(setExitCode),
|
19
|
+
UpdateCommand.GetCommand(setExitCode),
|
20
|
+
};
|
21
|
+
command.TreatUnmatchedTokensAsErrors = true;
|
22
|
+
|
23
|
+
var result = await command.InvokeAsync(args);
|
24
|
+
if (result != 0)
|
25
|
+
{
|
26
|
+
exitCode = result;
|
27
|
+
}
|
28
|
+
|
29
|
+
return exitCode;
|
30
|
+
}
|
31
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using System.Threading.Tasks;
|
4
|
+
|
5
|
+
using Xunit;
|
6
|
+
|
7
|
+
namespace NuGetUpdater.Cli.Test;
|
8
|
+
|
9
|
+
public partial class EntryPointTests
|
10
|
+
{
|
11
|
+
public class FrameworkCheck
|
12
|
+
{
|
13
|
+
[Theory]
|
14
|
+
[InlineData("net7.0", "net5.0")]
|
15
|
+
[InlineData("net7.0 net472", "net5.0 net461")]
|
16
|
+
[InlineData("net7.0 net472", "netstandard2.0")]
|
17
|
+
public Task Compatible(string projectTfms, string packageTfms)
|
18
|
+
=> Run(projectTfms, packageTfms, expectedExitCode: 0);
|
19
|
+
|
20
|
+
[Theory]
|
21
|
+
[InlineData("net5.0", "net7.0")]
|
22
|
+
[InlineData("net5.0 net461", "net7.0 net472")]
|
23
|
+
[InlineData("net5.0 net45", "netstandard2.0")]
|
24
|
+
public Task Incompatible(string projectTfms, string packageTfms)
|
25
|
+
=> Run(projectTfms, packageTfms, expectedExitCode: 1);
|
26
|
+
|
27
|
+
private static async Task Run(string projectTfms, string packageTfms, int expectedExitCode)
|
28
|
+
{
|
29
|
+
var args = new List<string>();
|
30
|
+
args.Add("framework-check");
|
31
|
+
args.Add("--project-tfms");
|
32
|
+
args.AddRange(projectTfms.Split(' ', StringSplitOptions.TrimEntries));
|
33
|
+
args.Add("--package-tfms");
|
34
|
+
args.AddRange(packageTfms.Split(' ', StringSplitOptions.TrimEntries));
|
35
|
+
args.Add("--verbose");
|
36
|
+
|
37
|
+
var actual = await Program.Main(args.ToArray());
|
38
|
+
|
39
|
+
Assert.Equal(expectedExitCode, actual);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
@@ -0,0 +1,323 @@
|
|
1
|
+
using System;
|
2
|
+
using System.IO;
|
3
|
+
using System.Text;
|
4
|
+
using System.Threading.Tasks;
|
5
|
+
|
6
|
+
using NuGetUpdater.Core.Test.Update;
|
7
|
+
|
8
|
+
using Xunit;
|
9
|
+
|
10
|
+
namespace NuGetUpdater.Cli.Test;
|
11
|
+
|
12
|
+
public partial class EntryPointTests
|
13
|
+
{
|
14
|
+
public class Update : UpdateWorkerTestBase
|
15
|
+
{
|
16
|
+
[Fact]
|
17
|
+
public async Task WithSolution()
|
18
|
+
{
|
19
|
+
await Run(path => new[]
|
20
|
+
{
|
21
|
+
"update",
|
22
|
+
"--repo-root",
|
23
|
+
path,
|
24
|
+
"--solution-or-project",
|
25
|
+
Path.Combine(path, "path/to/solution.sln"),
|
26
|
+
"--dependency",
|
27
|
+
"Newtonsoft.Json",
|
28
|
+
"--new-version",
|
29
|
+
"13.0.1",
|
30
|
+
"--previous-version",
|
31
|
+
"7.0.1",
|
32
|
+
},
|
33
|
+
new[]
|
34
|
+
{
|
35
|
+
("path/to/solution.sln", """
|
36
|
+
Microsoft Visual Studio Solution File, Format Version 12.00
|
37
|
+
# Visual Studio 14
|
38
|
+
VisualStudioVersion = 14.0.22705.0
|
39
|
+
MinimumVisualStudioVersion = 10.0.40219.1
|
40
|
+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "my", "my.csproj", "{782E0C0A-10D3-444D-9640-263D03D2B20C}"
|
41
|
+
EndProject
|
42
|
+
Global
|
43
|
+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
44
|
+
Debug|Any CPU = Debug|Any CPU
|
45
|
+
Release|Any CPU = Release|Any CPU
|
46
|
+
EndGlobalSection
|
47
|
+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
48
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
49
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
50
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
51
|
+
{782E0C0A-10D3-444D-9640-263D03D2B20C}.Release|Any CPU.Build.0 = Release|Any CPU
|
52
|
+
EndGlobalSection
|
53
|
+
GlobalSection(SolutionProperties) = preSolution
|
54
|
+
HideSolutionNode = FALSE
|
55
|
+
EndGlobalSection
|
56
|
+
EndGlobal
|
57
|
+
"""),
|
58
|
+
("path/to/my.csproj", """
|
59
|
+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
60
|
+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
61
|
+
<PropertyGroup>
|
62
|
+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
63
|
+
</PropertyGroup>
|
64
|
+
<ItemGroup>
|
65
|
+
<None Include="packages.config" />
|
66
|
+
</ItemGroup>
|
67
|
+
<ItemGroup>
|
68
|
+
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
|
69
|
+
<HintPath>packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
70
|
+
<Private>True</Private>
|
71
|
+
</Reference>
|
72
|
+
</ItemGroup>
|
73
|
+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
74
|
+
</Project>
|
75
|
+
"""),
|
76
|
+
("path/to/packages.config", """
|
77
|
+
<packages>
|
78
|
+
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
|
79
|
+
</packages>
|
80
|
+
""")
|
81
|
+
},
|
82
|
+
new[]
|
83
|
+
{
|
84
|
+
("path/to/my.csproj", """
|
85
|
+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
86
|
+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
87
|
+
<PropertyGroup>
|
88
|
+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
89
|
+
</PropertyGroup>
|
90
|
+
<ItemGroup>
|
91
|
+
<None Include="packages.config" />
|
92
|
+
</ItemGroup>
|
93
|
+
<ItemGroup>
|
94
|
+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
|
95
|
+
<HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
96
|
+
<Private>True</Private>
|
97
|
+
</Reference>
|
98
|
+
</ItemGroup>
|
99
|
+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
100
|
+
</Project>
|
101
|
+
"""),
|
102
|
+
("path/to/packages.config", """
|
103
|
+
<?xml version="1.0" encoding="utf-8"?>
|
104
|
+
<packages>
|
105
|
+
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net45" />
|
106
|
+
</packages>
|
107
|
+
""")
|
108
|
+
});
|
109
|
+
}
|
110
|
+
|
111
|
+
[Fact]
|
112
|
+
public async Task WithProject()
|
113
|
+
{
|
114
|
+
await Run(path => new[]
|
115
|
+
{
|
116
|
+
"update",
|
117
|
+
"--repo-root",
|
118
|
+
path,
|
119
|
+
"--solution-or-project",
|
120
|
+
Path.Combine(path, "path/to/my.csproj"),
|
121
|
+
"--dependency",
|
122
|
+
"Newtonsoft.Json",
|
123
|
+
"--new-version",
|
124
|
+
"13.0.1",
|
125
|
+
"--previous-version",
|
126
|
+
"7.0.1",
|
127
|
+
"--verbose"
|
128
|
+
},
|
129
|
+
new[]
|
130
|
+
{
|
131
|
+
("path/to/my.csproj", """
|
132
|
+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
133
|
+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
134
|
+
<PropertyGroup>
|
135
|
+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
136
|
+
</PropertyGroup>
|
137
|
+
<ItemGroup>
|
138
|
+
<None Include="packages.config" />
|
139
|
+
</ItemGroup>
|
140
|
+
<ItemGroup>
|
141
|
+
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
|
142
|
+
<HintPath>packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
143
|
+
<Private>True</Private>
|
144
|
+
</Reference>
|
145
|
+
</ItemGroup>
|
146
|
+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
147
|
+
</Project>
|
148
|
+
"""),
|
149
|
+
("path/to/packages.config", """
|
150
|
+
<packages>
|
151
|
+
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
|
152
|
+
</packages>
|
153
|
+
""")
|
154
|
+
},
|
155
|
+
new[]
|
156
|
+
{
|
157
|
+
("path/to/my.csproj", """
|
158
|
+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
159
|
+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
160
|
+
<PropertyGroup>
|
161
|
+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
162
|
+
</PropertyGroup>
|
163
|
+
<ItemGroup>
|
164
|
+
<None Include="packages.config" />
|
165
|
+
</ItemGroup>
|
166
|
+
<ItemGroup>
|
167
|
+
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
|
168
|
+
<HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
169
|
+
<Private>True</Private>
|
170
|
+
</Reference>
|
171
|
+
</ItemGroup>
|
172
|
+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
173
|
+
</Project>
|
174
|
+
"""),
|
175
|
+
("path/to/packages.config", """
|
176
|
+
<?xml version="1.0" encoding="utf-8"?>
|
177
|
+
<packages>
|
178
|
+
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net45" />
|
179
|
+
</packages>
|
180
|
+
""")
|
181
|
+
});
|
182
|
+
}
|
183
|
+
|
184
|
+
[Fact]
|
185
|
+
public async Task WithDirsProjAndDirectoryBuildPropsThatIsOutOfDirectoryButStillMatchingThePackage()
|
186
|
+
{
|
187
|
+
await Run(path => new[]
|
188
|
+
{
|
189
|
+
"update",
|
190
|
+
"--repo-root", path,
|
191
|
+
"--solution-or-project", $"{path}/some-dir/dirs.proj",
|
192
|
+
"--dependency", "NuGet.Versioning",
|
193
|
+
"--new-version", "6.6.1",
|
194
|
+
"--previous-version", "6.1.0",
|
195
|
+
"--verbose"
|
196
|
+
},
|
197
|
+
initialFiles: new[]
|
198
|
+
{
|
199
|
+
("some-dir/dirs.proj", """
|
200
|
+
<Project Sdk="Microsoft.Build.Traversal">
|
201
|
+
<ItemGroup>
|
202
|
+
<ProjectFile Include="project1/project.csproj" />
|
203
|
+
<ProjectReference Include="project2/project.csproj" />
|
204
|
+
</ItemGroup>
|
205
|
+
</Project>
|
206
|
+
"""),
|
207
|
+
("some-dir/project1/project.csproj", """
|
208
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
209
|
+
<PropertyGroup>
|
210
|
+
<OutputType>Exe</OutputType>
|
211
|
+
<TargetFramework>net6.0</TargetFramework>
|
212
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
213
|
+
<Nullable>enable</Nullable>
|
214
|
+
</PropertyGroup>
|
215
|
+
<ItemGroup>
|
216
|
+
<PackageReference Include="NuGet.Versioning" Version="6.1.0" />
|
217
|
+
</ItemGroup>
|
218
|
+
</Project>
|
219
|
+
"""),
|
220
|
+
("some-dir/project2/project.csproj", """
|
221
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
222
|
+
<PropertyGroup>
|
223
|
+
<OutputType>Exe</OutputType>
|
224
|
+
<TargetFramework>net6.0</TargetFramework>
|
225
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
226
|
+
<Nullable>enable</Nullable>
|
227
|
+
</PropertyGroup>
|
228
|
+
<ItemGroup>
|
229
|
+
<PackageReference Include="NuGet.Versioning" Version="6.1.0" />
|
230
|
+
</ItemGroup>
|
231
|
+
</Project>
|
232
|
+
"""),
|
233
|
+
("other-dir/Directory.Build.props", """
|
234
|
+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
235
|
+
|
236
|
+
<ItemGroup>
|
237
|
+
<PackageReference Include="NuGet.Versioning" Version="6.1.0" />
|
238
|
+
</ItemGroup>
|
239
|
+
|
240
|
+
</Project>
|
241
|
+
""")
|
242
|
+
},
|
243
|
+
expectedFiles: new[]
|
244
|
+
{
|
245
|
+
("some-dir/dirs.proj", """
|
246
|
+
<Project Sdk="Microsoft.Build.Traversal">
|
247
|
+
<ItemGroup>
|
248
|
+
<ProjectFile Include="project1/project.csproj" />
|
249
|
+
<ProjectReference Include="project2/project.csproj" />
|
250
|
+
</ItemGroup>
|
251
|
+
</Project>
|
252
|
+
"""),
|
253
|
+
("some-dir/project1/project.csproj", """
|
254
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
255
|
+
<PropertyGroup>
|
256
|
+
<OutputType>Exe</OutputType>
|
257
|
+
<TargetFramework>net6.0</TargetFramework>
|
258
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
259
|
+
<Nullable>enable</Nullable>
|
260
|
+
</PropertyGroup>
|
261
|
+
<ItemGroup>
|
262
|
+
<PackageReference Include="NuGet.Versioning" Version="6.6.1" />
|
263
|
+
</ItemGroup>
|
264
|
+
</Project>
|
265
|
+
"""),
|
266
|
+
("some-dir/project2/project.csproj", """
|
267
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
268
|
+
<PropertyGroup>
|
269
|
+
<OutputType>Exe</OutputType>
|
270
|
+
<TargetFramework>net6.0</TargetFramework>
|
271
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
272
|
+
<Nullable>enable</Nullable>
|
273
|
+
</PropertyGroup>
|
274
|
+
<ItemGroup>
|
275
|
+
<PackageReference Include="NuGet.Versioning" Version="6.6.1" />
|
276
|
+
</ItemGroup>
|
277
|
+
</Project>
|
278
|
+
"""),
|
279
|
+
("other-dir/Directory.Build.props", """
|
280
|
+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
281
|
+
|
282
|
+
<ItemGroup>
|
283
|
+
<PackageReference Include="NuGet.Versioning" Version="6.1.0" />
|
284
|
+
</ItemGroup>
|
285
|
+
|
286
|
+
</Project>
|
287
|
+
""")
|
288
|
+
}
|
289
|
+
);
|
290
|
+
}
|
291
|
+
|
292
|
+
private static async Task Run(Func<string, string[]> getArgs, (string Path, string Content)[] initialFiles, (string, string)[] expectedFiles)
|
293
|
+
{
|
294
|
+
var actualFiles = await RunUpdate(initialFiles, async (path) =>
|
295
|
+
{
|
296
|
+
var sb = new StringBuilder();
|
297
|
+
var writer = new StringWriter(sb);
|
298
|
+
|
299
|
+
var originalOut = Console.Out;
|
300
|
+
var originalErr = Console.Error;
|
301
|
+
Console.SetOut(writer);
|
302
|
+
Console.SetError(writer);
|
303
|
+
|
304
|
+
try
|
305
|
+
{
|
306
|
+
var args = getArgs(path);
|
307
|
+
var result = await Program.Main(args);
|
308
|
+
if (result != 0)
|
309
|
+
{
|
310
|
+
throw new Exception($"Program exited with code {result}.\nOutput:\n\n{sb}");
|
311
|
+
}
|
312
|
+
}
|
313
|
+
finally
|
314
|
+
{
|
315
|
+
Console.SetOut(originalOut);
|
316
|
+
Console.SetError(originalErr);
|
317
|
+
}
|
318
|
+
});
|
319
|
+
|
320
|
+
AssertContainsFiles(expectedFiles, actualFiles);
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
2
|
+
|
3
|
+
<PropertyGroup>
|
4
|
+
<TargetFramework>$(CommonTargetFramework)</TargetFramework>
|
5
|
+
<OutputType>Exe</OutputType>
|
6
|
+
<Nullable>enable</Nullable>
|
7
|
+
</PropertyGroup>
|
8
|
+
|
9
|
+
<ItemGroup>
|
10
|
+
<ProjectReference Include="..\NuGetUpdater.Cli\NuGetUpdater.Cli.csproj" />
|
11
|
+
<ProjectReference Include="..\NuGetUpdater.Core.Test\NuGetUpdater.Core.Test.csproj" />
|
12
|
+
</ItemGroup>
|
13
|
+
|
14
|
+
<ItemGroup>
|
15
|
+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
|
16
|
+
<PackageReference Include="xunit" Version="2.4.2" />
|
17
|
+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
|
18
|
+
</ItemGroup>
|
19
|
+
|
20
|
+
<ItemGroup>
|
21
|
+
<Content Include="..\xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
|
22
|
+
</ItemGroup>
|
23
|
+
|
24
|
+
</Project>
|
@@ -0,0 +1,97 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using System.IO;
|
4
|
+
using System.Text.RegularExpressions;
|
5
|
+
using System.Threading.Tasks;
|
6
|
+
|
7
|
+
using DiffPlex;
|
8
|
+
using DiffPlex.DiffBuilder;
|
9
|
+
using DiffPlex.DiffBuilder.Model;
|
10
|
+
|
11
|
+
namespace NuGetUpdater.Core;
|
12
|
+
|
13
|
+
internal abstract class BuildFile
|
14
|
+
{
|
15
|
+
public string RepoRootPath { get; }
|
16
|
+
public string Path { get; }
|
17
|
+
public string RepoRelativePath => System.IO.Path.GetRelativePath(RepoRootPath, Path);
|
18
|
+
|
19
|
+
public BuildFile(string repoRootPath, string path)
|
20
|
+
{
|
21
|
+
RepoRootPath = repoRootPath;
|
22
|
+
Path = path;
|
23
|
+
}
|
24
|
+
|
25
|
+
public abstract Task<bool> SaveAsync();
|
26
|
+
|
27
|
+
public static IEnumerable<Dependency> GetDependencies(BuildFile buildFile)
|
28
|
+
{
|
29
|
+
return buildFile switch
|
30
|
+
{
|
31
|
+
ProjectBuildFile projectBuildFile => projectBuildFile.GetDependencies(),
|
32
|
+
PackagesConfigBuildFile packagesConfigBuildFile => packagesConfigBuildFile.GetDependencies(),
|
33
|
+
GlobalJsonBuildFile globalJsonBuildFile => globalJsonBuildFile.GetDependencies(),
|
34
|
+
DotNetToolsJsonBuildFile dotnetToolsJsonBuildFile => dotnetToolsJsonBuildFile.GetDependencies(),
|
35
|
+
_ => throw new NotSupportedException($"Build files of type [{buildFile.GetType().Name}] are not supported.")
|
36
|
+
};
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
internal abstract partial class BuildFile<T>
|
41
|
+
: BuildFile where T : class
|
42
|
+
{
|
43
|
+
public T Contents { get; private set; }
|
44
|
+
|
45
|
+
private string _originalContentsText;
|
46
|
+
|
47
|
+
public BuildFile(string repoRootPath, string path, T contents) : base(repoRootPath, path)
|
48
|
+
{
|
49
|
+
Contents = contents;
|
50
|
+
_originalContentsText = GetContentsString(contents);
|
51
|
+
}
|
52
|
+
|
53
|
+
public void Update(T contents)
|
54
|
+
{
|
55
|
+
Contents = contents;
|
56
|
+
}
|
57
|
+
|
58
|
+
public override async Task<bool> SaveAsync()
|
59
|
+
{
|
60
|
+
var currentContentsText = GetContentsString(Contents);
|
61
|
+
|
62
|
+
if (!HasAnyNonWhitespaceChanges(_originalContentsText, currentContentsText))
|
63
|
+
{
|
64
|
+
return false;
|
65
|
+
}
|
66
|
+
|
67
|
+
await File.WriteAllTextAsync(Path, currentContentsText);
|
68
|
+
_originalContentsText = currentContentsText;
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
|
72
|
+
protected abstract string GetContentsString(T contents);
|
73
|
+
|
74
|
+
private static bool HasAnyNonWhitespaceChanges(string oldText, string newText)
|
75
|
+
{
|
76
|
+
// Ignore white space
|
77
|
+
oldText = WhitespaceRegex().Replace(oldText, string.Empty);
|
78
|
+
newText = WhitespaceRegex().Replace(newText, string.Empty);
|
79
|
+
|
80
|
+
var diffBuilder = new InlineDiffBuilder(new Differ());
|
81
|
+
var diff = diffBuilder.BuildDiffModel(oldText, newText);
|
82
|
+
foreach (var line in diff.Lines)
|
83
|
+
{
|
84
|
+
if (line.Type is ChangeType.Inserted ||
|
85
|
+
line.Type is ChangeType.Deleted ||
|
86
|
+
line.Type is ChangeType.Modified)
|
87
|
+
{
|
88
|
+
return true;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
return false;
|
93
|
+
}
|
94
|
+
|
95
|
+
[GeneratedRegex("\\s+")]
|
96
|
+
private static partial Regex WhitespaceRegex();
|
97
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
using System.IO;
|
3
|
+
using System.Linq;
|
4
|
+
using System.Text.Json.Nodes;
|
5
|
+
|
6
|
+
namespace NuGetUpdater.Core;
|
7
|
+
|
8
|
+
internal sealed class DotNetToolsJsonBuildFile : JsonBuildFile
|
9
|
+
{
|
10
|
+
public static DotNetToolsJsonBuildFile Open(string repoRootPath, string path, Logger logger)
|
11
|
+
=> new(repoRootPath, path, File.ReadAllText(path), logger);
|
12
|
+
|
13
|
+
public DotNetToolsJsonBuildFile(string repoRootPath, string path, string contents, Logger logger)
|
14
|
+
: base(repoRootPath, path, contents, logger)
|
15
|
+
{
|
16
|
+
}
|
17
|
+
|
18
|
+
public IEnumerable<KeyValuePair<string, JsonNode?>> Tools
|
19
|
+
=> Node.Value?["tools"]?.AsObject().ToArray() ?? Enumerable.Empty<KeyValuePair<string, JsonNode?>>();
|
20
|
+
|
21
|
+
public IEnumerable<Dependency> GetDependencies() => Tools.Select(
|
22
|
+
t => new Dependency(t.Key, t.Value?.AsObject()["version"]?.GetValue<string>() ?? string.Empty, DependencyType.DotNetTool));
|
23
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
using System.Collections.Generic;
|
2
|
+
using System.IO;
|
3
|
+
using System.Linq;
|
4
|
+
using System.Text.Json.Nodes;
|
5
|
+
|
6
|
+
namespace NuGetUpdater.Core;
|
7
|
+
|
8
|
+
internal sealed class GlobalJsonBuildFile : JsonBuildFile
|
9
|
+
{
|
10
|
+
public static GlobalJsonBuildFile Open(string repoRootPath, string path, Logger logger)
|
11
|
+
=> new(repoRootPath, path, File.ReadAllText(path), logger);
|
12
|
+
|
13
|
+
public GlobalJsonBuildFile(string repoRootPath, string path, string contents, Logger logger)
|
14
|
+
: base(repoRootPath, path, contents, logger)
|
15
|
+
{
|
16
|
+
}
|
17
|
+
|
18
|
+
public JsonObject? Sdk
|
19
|
+
{
|
20
|
+
get
|
21
|
+
{
|
22
|
+
return Node.Value is JsonObject root ? root["sdk"]?.AsObject() : null;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
public JsonObject? MSBuildSdks
|
27
|
+
{
|
28
|
+
get
|
29
|
+
{
|
30
|
+
return Node.Value is JsonObject root ? root["msbuild-sdks"]?.AsObject() : null;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
public IEnumerable<Dependency> GetDependencies() => MSBuildSdks?.AsObject().Select(
|
35
|
+
t => new Dependency(t.Key, t.Value?.GetValue<string>() ?? string.Empty, DependencyType.MSBuildSdk)) ?? Enumerable.Empty<Dependency>();
|
36
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Text.Json.Nodes;
|
3
|
+
|
4
|
+
using NuGetUpdater.Core.Utilities;
|
5
|
+
|
6
|
+
namespace NuGetUpdater.Core;
|
7
|
+
|
8
|
+
internal abstract class JsonBuildFile : BuildFile<string>
|
9
|
+
{
|
10
|
+
protected Lazy<JsonNode?> Node;
|
11
|
+
private readonly Logger logger;
|
12
|
+
|
13
|
+
public JsonBuildFile(string repoRootPath, string path, string contents, Logger logger)
|
14
|
+
: base(repoRootPath, path, contents)
|
15
|
+
{
|
16
|
+
Node = new Lazy<JsonNode?>(() => null);
|
17
|
+
this.logger = logger;
|
18
|
+
ResetNode();
|
19
|
+
}
|
20
|
+
|
21
|
+
protected override string GetContentsString(string _contents) => Contents;
|
22
|
+
|
23
|
+
public void UpdateProperty(string[] propertyPath, string newValue)
|
24
|
+
{
|
25
|
+
var updatedContents = JsonHelper.UpdateJsonProperty(Contents, propertyPath, newValue, StringComparison.OrdinalIgnoreCase);
|
26
|
+
Update(updatedContents);
|
27
|
+
ResetNode();
|
28
|
+
}
|
29
|
+
|
30
|
+
private void ResetNode()
|
31
|
+
{
|
32
|
+
Node = new Lazy<JsonNode?>(() =>
|
33
|
+
{
|
34
|
+
try
|
35
|
+
{
|
36
|
+
return JsonHelper.ParseNode(Contents);
|
37
|
+
}
|
38
|
+
catch (System.Text.Json.JsonException ex)
|
39
|
+
{
|
40
|
+
// We can't police that people have legal JSON files.
|
41
|
+
// If they don't, we just return null.
|
42
|
+
logger.Log($"Failed to parse JSON file: {RepoRelativePath}, got {ex}");
|
43
|
+
return null;
|
44
|
+
}
|
45
|
+
});
|
46
|
+
}
|
47
|
+
}
|