dependabot-nuget 0.251.0 → 0.252.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/helpers/lib/NuGetUpdater/Directory.Common.props +1 -0
- data/helpers/lib/NuGetUpdater/Directory.Packages.props +26 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/DiscoverCommand.cs +35 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/NuGetUpdater.Cli.csproj +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +4 -7
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Discover.cs +251 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/NuGetUpdater.Cli.Test.csproj +3 -3
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Dependency.cs +56 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyType.cs +1 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DirectoryPackagesPropsDiscovery.cs +69 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DirectoryPackagesPropsDiscoveryResult.cs +11 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs +217 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DotNetToolsJsonDiscovery.cs +30 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DotNetToolsJsonDiscoveryResult.cs +10 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/GlobalJsonDiscovery.cs +30 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/GlobalJsonDiscoveryResult.cs +10 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/IDiscoveryResult.cs +14 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/PackagesConfigDiscovery.cs +29 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/PackagesConfigDiscoveryResult.cs +10 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/ProjectDiscoveryResult.cs +13 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/SdkProjectDiscovery.cs +127 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/WorkspaceDiscoveryResult.cs +13 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/EvaluationResult.cs +8 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/EvaluationResultType.cs +9 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/BuildFile.cs +6 -8
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/DotNetToolsJsonBuildFile.cs +4 -7
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +24 -17
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/PackagesConfigBuildFile.cs +8 -13
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/ProjectBuildFile.cs +100 -19
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/XmlBuildFile.cs +2 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/NuGetUpdater.Core.csproj +6 -6
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Property.cs +6 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +23 -36
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +5 -10
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SdkPackageUpdater.cs +16 -21
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +4 -19
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/HashSetExtensions.cs +14 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ImmutableArrayExtensions.cs +18 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/JsonHelper.cs +0 -1
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +121 -68
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/NuGetHelper.cs +27 -4
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTestBase.cs +117 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.DotNetToolsJson.cs +91 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.GlobalJson.cs +71 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.PackagesConfig.cs +59 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.Project.cs +380 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs +306 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/ExpectedDiscoveryResults.cs +36 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/DotNetToolsJsonBuildFileTests.cs +1 -2
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +2 -3
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/PackagesConfigBuildFileTests.cs +4 -6
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/ProjectBuildFileTests.cs +6 -5
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/NuGetUpdater.Core.Test.csproj +4 -3
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TemporaryDirectory.cs +38 -6
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +12 -40
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/AssertEx.cs +272 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/DiffUtil.cs +266 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +195 -152
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterHelperTests.cs +7 -11
- data/lib/dependabot/nuget/discovery/dependency_details.rb +95 -0
- data/lib/dependabot/nuget/discovery/dependency_file_discovery.rb +126 -0
- data/lib/dependabot/nuget/discovery/directory_packages_props_discovery.rb +43 -0
- data/lib/dependabot/nuget/discovery/discovery_json_reader.rb +83 -0
- data/lib/dependabot/nuget/discovery/evaluation_details.rb +63 -0
- data/lib/dependabot/nuget/discovery/project_discovery.rb +71 -0
- data/lib/dependabot/nuget/discovery/property_details.rb +43 -0
- data/lib/dependabot/nuget/discovery/workspace_discovery.rb +66 -0
- data/lib/dependabot/nuget/file_parser.rb +19 -128
- data/lib/dependabot/nuget/file_updater.rb +28 -60
- data/lib/dependabot/nuget/native_helpers.rb +55 -0
- data/lib/dependabot/nuget/update_checker/compatibility_checker.rb +3 -8
- data/lib/dependabot/nuget/update_checker/dependency_finder.rb +1 -0
- data/lib/dependabot/nuget/update_checker/property_updater.rb +1 -0
- data/lib/dependabot/nuget/update_checker/tfm_finder.rb +17 -152
- data/lib/dependabot/nuget/update_checker/version_finder.rb +1 -6
- data/lib/dependabot/nuget/update_checker.rb +4 -1
- metadata +43 -11
- data/lib/dependabot/nuget/file_parser/dotnet_tools_json_parser.rb +0 -71
- data/lib/dependabot/nuget/file_parser/global_json_parser.rb +0 -68
- data/lib/dependabot/nuget/file_parser/packages_config_parser.rb +0 -92
- data/lib/dependabot/nuget/file_parser/project_file_parser.rb +0 -620
- data/lib/dependabot/nuget/file_parser/property_value_finder.rb +0 -225
- data/lib/dependabot/nuget/file_updater/property_value_updater.rb +0 -81
@@ -1,22 +1,17 @@
|
|
1
|
-
using System;
|
2
|
-
using System.Collections.Generic;
|
3
|
-
using System.IO;
|
4
|
-
using System.Linq;
|
5
|
-
|
6
1
|
using Microsoft.Language.Xml;
|
7
2
|
|
8
3
|
namespace NuGetUpdater.Core;
|
9
4
|
|
10
5
|
internal sealed class PackagesConfigBuildFile : XmlBuildFile
|
11
6
|
{
|
12
|
-
public static PackagesConfigBuildFile Open(string
|
13
|
-
=> Parse(
|
7
|
+
public static PackagesConfigBuildFile Open(string basePath, string path)
|
8
|
+
=> Parse(basePath, path, File.ReadAllText(path));
|
14
9
|
|
15
|
-
public static PackagesConfigBuildFile Parse(string
|
16
|
-
=> new(
|
10
|
+
public static PackagesConfigBuildFile Parse(string basePath, string path, string xml)
|
11
|
+
=> new(basePath, path, Parser.ParseText(xml));
|
17
12
|
|
18
|
-
public PackagesConfigBuildFile(string
|
19
|
-
: base(
|
13
|
+
public PackagesConfigBuildFile(string basePath, string path, XmlDocumentSyntax contents)
|
14
|
+
: base(basePath, path, contents)
|
20
15
|
{
|
21
16
|
}
|
22
17
|
|
@@ -27,6 +22,6 @@ internal sealed class PackagesConfigBuildFile : XmlBuildFile
|
|
27
22
|
.Select(p => new Dependency(
|
28
23
|
p.GetAttributeValue("id", StringComparison.OrdinalIgnoreCase),
|
29
24
|
p.GetAttributeValue("version", StringComparison.OrdinalIgnoreCase),
|
30
|
-
DependencyType.
|
31
|
-
(p.GetAttribute("developmentDependency", StringComparison.OrdinalIgnoreCase)?.Value ?? "false").Equals(true.ToString(), StringComparison.OrdinalIgnoreCase)));
|
25
|
+
DependencyType.PackagesConfig,
|
26
|
+
IsDevDependency: (p.GetAttribute("developmentDependency", StringComparison.OrdinalIgnoreCase)?.Value ?? "false").Equals(true.ToString(), StringComparison.OrdinalIgnoreCase)));
|
32
27
|
}
|
@@ -1,33 +1,36 @@
|
|
1
|
-
using System;
|
2
|
-
using System.Collections.Generic;
|
3
|
-
using System.IO;
|
4
|
-
using System.Linq;
|
5
|
-
|
6
1
|
using Microsoft.Language.Xml;
|
7
2
|
|
8
3
|
namespace NuGetUpdater.Core;
|
9
4
|
|
10
5
|
internal sealed class ProjectBuildFile : XmlBuildFile
|
11
6
|
{
|
12
|
-
public static ProjectBuildFile Open(string
|
13
|
-
=> Parse(
|
7
|
+
public static ProjectBuildFile Open(string basePath, string path)
|
8
|
+
=> Parse(basePath, path, File.ReadAllText(path));
|
14
9
|
|
15
|
-
public static ProjectBuildFile Parse(string
|
16
|
-
=> new(
|
10
|
+
public static ProjectBuildFile Parse(string basePath, string path, string xml)
|
11
|
+
=> new(basePath, path, Parser.ParseText(xml));
|
17
12
|
|
18
|
-
public ProjectBuildFile(string
|
19
|
-
: base(
|
13
|
+
public ProjectBuildFile(string basePath, string path, XmlDocumentSyntax contents)
|
14
|
+
: base(basePath, path, contents)
|
20
15
|
{
|
21
16
|
}
|
22
17
|
|
23
|
-
public
|
18
|
+
public IXmlElementSyntax ProjectNode => Contents.RootSyntax;
|
19
|
+
|
20
|
+
public IEnumerable<IXmlElementSyntax> SdkNodes => ProjectNode
|
21
|
+
.GetElements("Sdk", StringComparison.OrdinalIgnoreCase);
|
22
|
+
|
23
|
+
public IEnumerable<IXmlElementSyntax> ImportNodes => ProjectNode
|
24
|
+
.GetElements("Import", StringComparison.OrdinalIgnoreCase);
|
25
|
+
|
26
|
+
public IEnumerable<IXmlElementSyntax> PropertyNodes => ProjectNode
|
24
27
|
.GetElements("PropertyGroup", StringComparison.OrdinalIgnoreCase)
|
25
28
|
.SelectMany(e => e.Elements);
|
26
29
|
|
27
30
|
public IEnumerable<KeyValuePair<string, string>> GetProperties() => PropertyNodes
|
28
31
|
.Select(e => new KeyValuePair<string, string>(e.Name, e.GetContentValue()));
|
29
32
|
|
30
|
-
public IEnumerable<IXmlElementSyntax> ItemNodes =>
|
33
|
+
public IEnumerable<IXmlElementSyntax> ItemNodes => ProjectNode
|
31
34
|
.GetElements("ItemGroup", StringComparison.OrdinalIgnoreCase)
|
32
35
|
.SelectMany(e => e.Elements);
|
33
36
|
|
@@ -36,14 +39,67 @@ internal sealed class ProjectBuildFile : XmlBuildFile
|
|
36
39
|
e.Name.Equals("GlobalPackageReference", StringComparison.OrdinalIgnoreCase) ||
|
37
40
|
e.Name.Equals("PackageVersion", StringComparison.OrdinalIgnoreCase));
|
38
41
|
|
39
|
-
public IEnumerable<Dependency> GetDependencies()
|
40
|
-
|
41
|
-
|
42
|
+
public IEnumerable<Dependency> GetDependencies()
|
43
|
+
{
|
44
|
+
var sdkDependencies = GetSdkDependencies();
|
45
|
+
var packageDependencies = PackageItemNodes
|
46
|
+
.Select(GetPackageDependency)
|
47
|
+
.OfType<Dependency>();
|
48
|
+
return sdkDependencies.Concat(packageDependencies);
|
49
|
+
}
|
42
50
|
|
43
|
-
private
|
51
|
+
private IEnumerable<Dependency> GetSdkDependencies()
|
44
52
|
{
|
45
|
-
|
46
|
-
|
53
|
+
List<Dependency> dependencies = [];
|
54
|
+
if (ProjectNode.GetAttributeValueCaseInsensitive("Sdk") is string sdk)
|
55
|
+
{
|
56
|
+
dependencies.Add(GetMSBuildSdkDependency(sdk));
|
57
|
+
}
|
58
|
+
|
59
|
+
foreach (var sdkNode in SdkNodes)
|
60
|
+
{
|
61
|
+
var name = sdkNode.GetAttributeValueCaseInsensitive("Name");
|
62
|
+
var version = sdkNode.GetAttributeValueCaseInsensitive("Version");
|
63
|
+
|
64
|
+
if (name is not null)
|
65
|
+
{
|
66
|
+
dependencies.Add(GetMSBuildSdkDependency(name, version));
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
foreach (var importNode in ImportNodes)
|
71
|
+
{
|
72
|
+
var name = importNode.GetAttributeValueCaseInsensitive("Name");
|
73
|
+
var version = importNode.GetAttributeValueCaseInsensitive("Version");
|
74
|
+
|
75
|
+
if (name is not null)
|
76
|
+
{
|
77
|
+
dependencies.Add(GetMSBuildSdkDependency(name, version));
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
return dependencies;
|
82
|
+
}
|
83
|
+
|
84
|
+
private static Dependency GetMSBuildSdkDependency(string name, string? version = null)
|
85
|
+
{
|
86
|
+
var parts = name.Split('/');
|
87
|
+
return parts.Length == 2
|
88
|
+
? new Dependency(parts[0], parts[1], DependencyType.MSBuildSdk)
|
89
|
+
: new Dependency(name, version, DependencyType.MSBuildSdk);
|
90
|
+
}
|
91
|
+
|
92
|
+
private static Dependency? GetPackageDependency(IXmlElementSyntax element)
|
93
|
+
{
|
94
|
+
var isUpdate = false;
|
95
|
+
|
96
|
+
var name = element.GetAttributeOrSubElementValue("Include", StringComparison.OrdinalIgnoreCase);
|
97
|
+
if (name is null)
|
98
|
+
{
|
99
|
+
isUpdate = true;
|
100
|
+
name = element.GetAttributeOrSubElementValue("Update", StringComparison.OrdinalIgnoreCase);
|
101
|
+
}
|
102
|
+
|
47
103
|
if (name is null || name.StartsWith("@("))
|
48
104
|
{
|
49
105
|
return null;
|
@@ -61,6 +117,7 @@ internal sealed class ProjectBuildFile : XmlBuildFile
|
|
61
117
|
Name: name,
|
62
118
|
Version: version?.Length == 0 ? null : version,
|
63
119
|
Type: GetDependencyType(element.Name),
|
120
|
+
IsUpdate: isUpdate,
|
64
121
|
IsOverride: isVersionOverride);
|
65
122
|
}
|
66
123
|
|
@@ -92,4 +149,28 @@ internal sealed class ProjectBuildFile : XmlBuildFile
|
|
92
149
|
(_, n) => n.WithContent(n.GetContentValue().Replace("/", "\\")).AsNode);
|
93
150
|
Update(updatedXml);
|
94
151
|
}
|
152
|
+
|
153
|
+
public ProjectBuildFileType GetFileType()
|
154
|
+
{
|
155
|
+
var extension = System.IO.Path.GetExtension(Path);
|
156
|
+
return extension.ToLower() switch
|
157
|
+
{
|
158
|
+
".csproj" => ProjectBuildFileType.Project,
|
159
|
+
".vbproj" => ProjectBuildFileType.Project,
|
160
|
+
".fsproj" => ProjectBuildFileType.Project,
|
161
|
+
".proj" => ProjectBuildFileType.Proj,
|
162
|
+
".props" => ProjectBuildFileType.Props,
|
163
|
+
".targets" => ProjectBuildFileType.Targets,
|
164
|
+
_ => ProjectBuildFileType.Unknown
|
165
|
+
};
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
public enum ProjectBuildFileType
|
170
|
+
{
|
171
|
+
Unknown,
|
172
|
+
Proj,
|
173
|
+
Project,
|
174
|
+
Props,
|
175
|
+
Targets
|
95
176
|
}
|
@@ -4,8 +4,8 @@ namespace NuGetUpdater.Core;
|
|
4
4
|
|
5
5
|
internal abstract class XmlBuildFile : BuildFile<XmlDocumentSyntax>
|
6
6
|
{
|
7
|
-
public XmlBuildFile(string
|
8
|
-
: base(
|
7
|
+
public XmlBuildFile(string basePath, string path, XmlDocumentSyntax contents)
|
8
|
+
: base(basePath, path, contents)
|
9
9
|
{
|
10
10
|
}
|
11
11
|
|
@@ -12,12 +12,12 @@
|
|
12
12
|
</ItemGroup>
|
13
13
|
|
14
14
|
<ItemGroup>
|
15
|
-
<PackageReference Include="GuiLabs.Language.Xml"
|
16
|
-
<PackageReference Include="DiffPlex"
|
17
|
-
<PackageReference Include="Microsoft.Build.Locator"
|
18
|
-
<PackageReference Include="Microsoft.Build"
|
19
|
-
<PackageReference Include="Microsoft.Build.Utilities.Core"
|
20
|
-
<PackageReference Include="NuGet.Core"
|
15
|
+
<PackageReference Include="GuiLabs.Language.Xml" />
|
16
|
+
<PackageReference Include="DiffPlex" />
|
17
|
+
<PackageReference Include="Microsoft.Build.Locator" />
|
18
|
+
<PackageReference Include="Microsoft.Build" ExcludeAssets="Runtime" PrivateAssets="All" />
|
19
|
+
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="Runtime" PrivateAssets="All" />
|
20
|
+
<PackageReference Include="NuGet.Core" Aliases="CoreV2" />
|
21
21
|
</ItemGroup>
|
22
22
|
|
23
23
|
<ItemGroup>
|
@@ -1,59 +1,46 @@
|
|
1
|
-
using System;
|
2
|
-
using System.Collections.Immutable;
|
3
|
-
using System.Linq;
|
4
|
-
using System.Threading.Tasks;
|
5
|
-
|
6
1
|
namespace NuGetUpdater.Core;
|
7
2
|
|
8
3
|
internal static class DotNetToolsJsonUpdater
|
9
4
|
{
|
10
|
-
public static async Task UpdateDependencyAsync(
|
5
|
+
public static async Task UpdateDependencyAsync(
|
6
|
+
string repoRootPath,
|
7
|
+
string workspacePath,
|
8
|
+
string dependencyName,
|
9
|
+
string previousDependencyVersion,
|
10
|
+
string newDependencyVersion,
|
11
11
|
Logger logger)
|
12
12
|
{
|
13
|
-
|
14
|
-
if (buildFiles.Length == 0)
|
13
|
+
if (!MSBuildHelper.TryGetDotNetToolsJsonPath(repoRootPath, workspacePath, out var dotnetToolsJsonPath))
|
15
14
|
{
|
16
|
-
logger.Log(" No dotnet-tools.json
|
15
|
+
logger.Log(" No dotnet-tools.json file found.");
|
17
16
|
return;
|
18
17
|
}
|
19
18
|
|
20
|
-
|
19
|
+
var dotnetToolsJsonFile = DotNetToolsJsonBuildFile.Open(repoRootPath, dotnetToolsJsonPath, logger);
|
21
20
|
|
21
|
+
logger.Log($" Updating [{dotnetToolsJsonFile.RelativePath}] file.");
|
22
22
|
|
23
|
-
var
|
24
|
-
|
25
|
-
.ToImmutableArray();
|
26
|
-
if (filesToUpdate.Length == 0)
|
23
|
+
var containsDependency = dotnetToolsJsonFile.GetDependencies().Any(d => d.Name.Equals(dependencyName, StringComparison.OrdinalIgnoreCase));
|
24
|
+
if (!containsDependency)
|
27
25
|
{
|
28
|
-
logger.Log($" Dependency [{dependencyName}] not found
|
26
|
+
logger.Log($" Dependency [{dependencyName}] not found.");
|
29
27
|
return;
|
30
28
|
}
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
var tool = buildFile.Tools
|
35
|
-
.Single(kvp => kvp.Key.Equals(dependencyName, StringComparison.OrdinalIgnoreCase));
|
30
|
+
var tool = dotnetToolsJsonFile.Tools
|
31
|
+
.Single(kvp => kvp.Key.Equals(dependencyName, StringComparison.OrdinalIgnoreCase));
|
36
32
|
|
37
|
-
|
33
|
+
var toolObject = tool.Value?.AsObject();
|
38
34
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
if (toolObject is not null &&
|
36
|
+
toolObject["version"]?.GetValue<string>() == previousDependencyVersion)
|
37
|
+
{
|
38
|
+
dotnetToolsJsonFile.UpdateProperty(["tools", dependencyName, "version"], newDependencyVersion);
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
}
|
40
|
+
if (await dotnetToolsJsonFile.SaveAsync())
|
41
|
+
{
|
42
|
+
logger.Log($" Saved [{dotnetToolsJsonFile.RelativePath}].");
|
48
43
|
}
|
49
44
|
}
|
50
45
|
}
|
51
|
-
|
52
|
-
private static ImmutableArray<DotNetToolsJsonBuildFile> LoadBuildFiles(string repoRootPath, string workspacePath, Logger logger)
|
53
|
-
{
|
54
|
-
var dotnetToolsJsonPath = PathHelper.GetFileInDirectoryOrParent(workspacePath, repoRootPath, "./.config/dotnet-tools.json");
|
55
|
-
return dotnetToolsJsonPath is not null
|
56
|
-
? [DotNetToolsJsonBuildFile.Open(repoRootPath, dotnetToolsJsonPath, logger)]
|
57
|
-
: [];
|
58
|
-
}
|
59
46
|
}
|
@@ -1,29 +1,24 @@
|
|
1
|
-
using System;
|
2
|
-
using System.IO;
|
3
|
-
using System.Linq;
|
4
|
-
using System.Threading.Tasks;
|
5
|
-
|
6
1
|
namespace NuGetUpdater.Core;
|
7
2
|
|
8
3
|
internal static class GlobalJsonUpdater
|
9
4
|
{
|
10
5
|
public static async Task UpdateDependencyAsync(
|
11
6
|
string repoRootPath,
|
12
|
-
string
|
7
|
+
string workspacePath,
|
13
8
|
string dependencyName,
|
14
9
|
string previousDependencyVersion,
|
15
10
|
string newDependencyVersion,
|
16
11
|
Logger logger)
|
17
12
|
{
|
18
|
-
if (!
|
13
|
+
if (!MSBuildHelper.TryGetGlobalJsonPath(repoRootPath, workspacePath, out var globalJsonPath))
|
19
14
|
{
|
20
|
-
logger.Log(
|
15
|
+
logger.Log(" No global.json file found.");
|
21
16
|
return;
|
22
17
|
}
|
23
18
|
|
24
19
|
var globalJsonFile = GlobalJsonBuildFile.Open(repoRootPath, globalJsonPath, logger);
|
25
20
|
|
26
|
-
logger.Log($" Updating [{globalJsonFile.
|
21
|
+
logger.Log($" Updating [{globalJsonFile.RelativePath}] file.");
|
27
22
|
|
28
23
|
var containsDependency = globalJsonFile.GetDependencies().Any(d => d.Name.Equals(dependencyName, StringComparison.OrdinalIgnoreCase));
|
29
24
|
if (!containsDependency)
|
@@ -48,7 +43,7 @@ internal static class GlobalJsonUpdater
|
|
48
43
|
|
49
44
|
if (await globalJsonFile.SaveAsync())
|
50
45
|
{
|
51
|
-
logger.Log($" Saved [{globalJsonFile.
|
46
|
+
logger.Log($" Saved [{globalJsonFile.RelativePath}].");
|
52
47
|
}
|
53
48
|
}
|
54
49
|
}
|
@@ -1,9 +1,4 @@
|
|
1
|
-
using System;
|
2
|
-
using System.Collections.Generic;
|
3
1
|
using System.Collections.Immutable;
|
4
|
-
using System.IO;
|
5
|
-
using System.Linq;
|
6
|
-
using System.Threading.Tasks;
|
7
2
|
|
8
3
|
using Microsoft.Language.Xml;
|
9
4
|
|
@@ -25,7 +20,7 @@ internal static class SdkPackageUpdater
|
|
25
20
|
// SDK-style project, modify the XML directly
|
26
21
|
logger.Log(" Running for SDK-style project");
|
27
22
|
|
28
|
-
var buildFiles = await MSBuildHelper.
|
23
|
+
var buildFiles = await MSBuildHelper.LoadBuildFilesAsync(repoRootPath, projectPath);
|
29
24
|
var tfms = MSBuildHelper.GetTargetFrameworkMonikers(buildFiles);
|
30
25
|
|
31
26
|
// Get the set of all top-level dependencies in the current project
|
@@ -84,7 +79,7 @@ internal static class SdkPackageUpdater
|
|
84
79
|
tfm,
|
85
80
|
topLevelDependencies,
|
86
81
|
logger);
|
87
|
-
foreach (var (packageName, packageVersion, _, _, _, _) in dependencies)
|
82
|
+
foreach (var (packageName, packageVersion, _, _, _, _, _, _, _, _) in dependencies)
|
88
83
|
{
|
89
84
|
if (packageVersion is null)
|
90
85
|
{
|
@@ -269,7 +264,7 @@ internal static class SdkPackageUpdater
|
|
269
264
|
var packagesAndVersions = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
270
265
|
foreach (var (_, dependencies) in tfmsAndDependencies)
|
271
266
|
{
|
272
|
-
foreach (var (packageName, packageVersion, _, _, _, _) in dependencies)
|
267
|
+
foreach (var (packageName, packageVersion, _, _, _, _, _, _, _, _) in dependencies)
|
273
268
|
{
|
274
269
|
if (packagesAndVersions.TryGetValue(packageName, out var existingVersion) &&
|
275
270
|
existingVersion != packageVersion)
|
@@ -356,12 +351,12 @@ internal static class SdkPackageUpdater
|
|
356
351
|
var currentVersion = versionAttribute.Value.TrimStart('[', '(').TrimEnd(']', ')');
|
357
352
|
if (currentVersion.Contains(',') || currentVersion.Contains('*'))
|
358
353
|
{
|
359
|
-
logger.Log($" Found unsupported [{packageNode.Name}] version attribute value [{versionAttribute.Value}] in [{buildFile.
|
354
|
+
logger.Log($" Found unsupported [{packageNode.Name}] version attribute value [{versionAttribute.Value}] in [{buildFile.RelativePath}].");
|
360
355
|
foundUnsupported = true;
|
361
356
|
}
|
362
357
|
else if (string.Equals(currentVersion, previousDependencyVersion, StringComparison.Ordinal))
|
363
358
|
{
|
364
|
-
logger.Log($" Found incorrect [{packageNode.Name}] version attribute in [{buildFile.
|
359
|
+
logger.Log($" Found incorrect [{packageNode.Name}] version attribute in [{buildFile.RelativePath}].");
|
365
360
|
updateNodes.Add(versionAttribute);
|
366
361
|
}
|
367
362
|
else if (previousDependencyVersion == null && NuGetVersion.TryParse(currentVersion, out var previousVersion))
|
@@ -371,13 +366,13 @@ internal static class SdkPackageUpdater
|
|
371
366
|
{
|
372
367
|
previousPackageVersion = currentVersion;
|
373
368
|
|
374
|
-
logger.Log($" Found incorrect peer [{packageNode.Name}] version attribute in [{buildFile.
|
369
|
+
logger.Log($" Found incorrect peer [{packageNode.Name}] version attribute in [{buildFile.RelativePath}].");
|
375
370
|
updateNodes.Add(versionAttribute);
|
376
371
|
}
|
377
372
|
}
|
378
373
|
else if (string.Equals(currentVersion, newDependencyVersion, StringComparison.Ordinal))
|
379
374
|
{
|
380
|
-
logger.Log($" Found correct [{packageNode.Name}] version attribute in [{buildFile.
|
375
|
+
logger.Log($" Found correct [{packageNode.Name}] version attribute in [{buildFile.RelativePath}].");
|
381
376
|
foundCorrect = true;
|
382
377
|
}
|
383
378
|
}
|
@@ -394,12 +389,12 @@ internal static class SdkPackageUpdater
|
|
394
389
|
var currentVersion = versionValue.TrimStart('[', '(').TrimEnd(']', ')');
|
395
390
|
if (currentVersion.Contains(',') || currentVersion.Contains('*'))
|
396
391
|
{
|
397
|
-
logger.Log($" Found unsupported [{packageNode.Name}] version node value [{versionValue}] in [{buildFile.
|
392
|
+
logger.Log($" Found unsupported [{packageNode.Name}] version node value [{versionValue}] in [{buildFile.RelativePath}].");
|
398
393
|
foundUnsupported = true;
|
399
394
|
}
|
400
395
|
else if (currentVersion == previousDependencyVersion)
|
401
396
|
{
|
402
|
-
logger.Log($" Found incorrect [{packageNode.Name}] version node in [{buildFile.
|
397
|
+
logger.Log($" Found incorrect [{packageNode.Name}] version node in [{buildFile.RelativePath}].");
|
403
398
|
if (versionElement is XmlElementSyntax elementSyntax)
|
404
399
|
{
|
405
400
|
updateNodes.Add(elementSyntax);
|
@@ -416,7 +411,7 @@ internal static class SdkPackageUpdater
|
|
416
411
|
{
|
417
412
|
previousPackageVersion = currentVersion;
|
418
413
|
|
419
|
-
logger.Log($" Found incorrect peer [{packageNode.Name}] version node in [{buildFile.
|
414
|
+
logger.Log($" Found incorrect peer [{packageNode.Name}] version node in [{buildFile.RelativePath}].");
|
420
415
|
if (versionElement is XmlElementSyntax elementSyntax)
|
421
416
|
{
|
422
417
|
updateNodes.Add(elementSyntax);
|
@@ -430,7 +425,7 @@ internal static class SdkPackageUpdater
|
|
430
425
|
}
|
431
426
|
else if (currentVersion == newDependencyVersion)
|
432
427
|
{
|
433
|
-
logger.Log($" Found correct [{packageNode.Name}] version node in [{buildFile.
|
428
|
+
logger.Log($" Found correct [{packageNode.Name}] version node in [{buildFile.RelativePath}].");
|
434
429
|
foundCorrect = true;
|
435
430
|
}
|
436
431
|
}
|
@@ -506,12 +501,12 @@ internal static class SdkPackageUpdater
|
|
506
501
|
var currentVersion = propertyContents.TrimStart('[', '(').TrimEnd(']', ')');
|
507
502
|
if (currentVersion.Contains(',') || currentVersion.Contains('*'))
|
508
503
|
{
|
509
|
-
logger.Log($" Found unsupported version property [{propertyElement.Name}] value [{propertyContents}] in [{buildFile.
|
504
|
+
logger.Log($" Found unsupported version property [{propertyElement.Name}] value [{propertyContents}] in [{buildFile.RelativePath}].");
|
510
505
|
foundUnsupported = true;
|
511
506
|
}
|
512
507
|
else if (currentVersion == previousDependencyVersion)
|
513
508
|
{
|
514
|
-
logger.Log($" Found incorrect version property [{propertyElement.Name}] in [{buildFile.
|
509
|
+
logger.Log($" Found incorrect version property [{propertyElement.Name}] in [{buildFile.RelativePath}].");
|
515
510
|
updateProperties.Add((XmlElementSyntax)propertyElement.AsNode);
|
516
511
|
}
|
517
512
|
else if (previousDependencyVersion is null && NuGetVersion.TryParse(currentVersion, out var previousVersion))
|
@@ -521,13 +516,13 @@ internal static class SdkPackageUpdater
|
|
521
516
|
{
|
522
517
|
previousPackageVersion = currentVersion;
|
523
518
|
|
524
|
-
logger.Log($" Found incorrect peer version property [{propertyElement.Name}] in [{buildFile.
|
519
|
+
logger.Log($" Found incorrect peer version property [{propertyElement.Name}] in [{buildFile.RelativePath}].");
|
525
520
|
updateProperties.Add((XmlElementSyntax)propertyElement.AsNode);
|
526
521
|
}
|
527
522
|
}
|
528
523
|
else if (currentVersion == newDependencyVersion)
|
529
524
|
{
|
530
|
-
logger.Log($" Found correct version property [{propertyElement.Name}] in [{buildFile.
|
525
|
+
logger.Log($" Found correct version property [{propertyElement.Name}] in [{buildFile.RelativePath}].");
|
531
526
|
foundCorrect = true;
|
532
527
|
}
|
533
528
|
}
|
@@ -585,7 +580,7 @@ internal static class SdkPackageUpdater
|
|
585
580
|
{
|
586
581
|
if (await buildFile.SaveAsync())
|
587
582
|
{
|
588
|
-
logger.Log($" Saved [{buildFile.
|
583
|
+
logger.Log($" Saved [{buildFile.RelativePath}].");
|
589
584
|
}
|
590
585
|
}
|
591
586
|
}
|
@@ -1,15 +1,8 @@
|
|
1
|
-
using System;
|
2
|
-
using System.Collections.Generic;
|
3
|
-
using System.IO;
|
4
|
-
using System.Linq;
|
5
|
-
using System.Threading.Tasks;
|
6
|
-
|
7
1
|
namespace NuGetUpdater.Core;
|
8
2
|
|
9
3
|
public class UpdaterWorker
|
10
4
|
{
|
11
5
|
private readonly Logger _logger;
|
12
|
-
private readonly HashSet<string> _processedGlobalJsonPaths = new(StringComparer.OrdinalIgnoreCase);
|
13
6
|
private readonly HashSet<string> _processedProjectPaths = new(StringComparer.OrdinalIgnoreCase);
|
14
7
|
|
15
8
|
public UpdaterWorker(Logger logger)
|
@@ -29,6 +22,7 @@ public class UpdaterWorker
|
|
29
22
|
if (!isTransitive)
|
30
23
|
{
|
31
24
|
await DotNetToolsJsonUpdater.UpdateDependencyAsync(repoRootPath, workspacePath, dependencyName, previousDependencyVersion, newDependencyVersion, _logger);
|
25
|
+
await GlobalJsonUpdater.UpdateDependencyAsync(repoRootPath, workspacePath, dependencyName, previousDependencyVersion, newDependencyVersion, _logger);
|
32
26
|
}
|
33
27
|
|
34
28
|
var extension = Path.GetExtension(workspacePath).ToLowerInvariant();
|
@@ -50,7 +44,8 @@ public class UpdaterWorker
|
|
50
44
|
break;
|
51
45
|
}
|
52
46
|
|
53
|
-
|
47
|
+
_logger.Log("Update complete.");
|
48
|
+
|
54
49
|
_processedProjectPaths.Clear();
|
55
50
|
}
|
56
51
|
|
@@ -139,22 +134,12 @@ public class UpdaterWorker
|
|
139
134
|
|
140
135
|
_logger.Log($"Updating project [{projectPath}]");
|
141
136
|
|
142
|
-
if (
|
143
|
-
&& MSBuildHelper.GetGlobalJsonPath(repoRootPath, projectPath) is { } globalJsonPath
|
144
|
-
&& !_processedGlobalJsonPaths.Contains(globalJsonPath))
|
145
|
-
{
|
146
|
-
_processedGlobalJsonPaths.Add(globalJsonPath);
|
147
|
-
await GlobalJsonUpdater.UpdateDependencyAsync(repoRootPath, globalJsonPath, dependencyName, previousDependencyVersion, newDependencyVersion, _logger);
|
148
|
-
}
|
149
|
-
|
150
|
-
if (NuGetHelper.HasPackagesConfigFile(projectPath))
|
137
|
+
if (NuGetHelper.TryGetPackagesConfigFile(projectPath, out _))
|
151
138
|
{
|
152
139
|
await PackagesConfigUpdater.UpdateDependencyAsync(repoRootPath, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive, _logger);
|
153
140
|
}
|
154
141
|
|
155
142
|
// Some repos use a mix of packages.config and PackageReference
|
156
143
|
await SdkPackageUpdater.UpdateDependencyAsync(repoRootPath, projectPath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive, _logger);
|
157
|
-
|
158
|
-
_logger.Log("Update complete.");
|
159
144
|
}
|
160
145
|
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
using System.Collections.Immutable;
|
2
|
+
|
3
|
+
namespace NuGetUpdater.Core.Utilities;
|
4
|
+
|
5
|
+
public static class HashSetExtensions
|
6
|
+
{
|
7
|
+
public static void AddRange<T>(this HashSet<T> hashSet, IEnumerable<T> items)
|
8
|
+
{
|
9
|
+
foreach (var item in items)
|
10
|
+
{
|
11
|
+
hashSet.Add(item);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
using System.Collections.Immutable;
|
2
|
+
|
3
|
+
namespace NuGetUpdater.Core.Utilities;
|
4
|
+
|
5
|
+
public static class ImmutableArrayExtensions
|
6
|
+
{
|
7
|
+
public static bool SequenceEqual<T>(this ImmutableArray<T>? expected, ImmutableArray<T>? actual, IEqualityComparer<T>? equalityComparer = null)
|
8
|
+
{
|
9
|
+
if (expected is null)
|
10
|
+
{
|
11
|
+
return actual is null;
|
12
|
+
}
|
13
|
+
else
|
14
|
+
{
|
15
|
+
return actual is not null && expected.Value.SequenceEqual(actual.Value, equalityComparer);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|