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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/helpers/build +45 -0
  3. data/helpers/lib/NuGetUpdater/.editorconfig +364 -0
  4. data/helpers/lib/NuGetUpdater/.gitignore +5 -0
  5. data/helpers/lib/NuGetUpdater/Directory.Build.props +10 -0
  6. data/helpers/lib/NuGetUpdater/Directory.Common.props +16 -0
  7. data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Build.props +14 -0
  8. data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Build.targets +7 -0
  9. data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Packages.props +29 -0
  10. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Build.Tasks/NuGet.Build.Tasks.csproj +27 -0
  11. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/AssemblyMetadataExtractor.cs +203 -0
  12. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/NuGet.CommandLine.csproj +33 -0
  13. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Commands/NuGet.Commands.csproj +26 -0
  14. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Common/NuGet.Common.csproj +21 -0
  15. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Config +6 -0
  16. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Configuration/NuGet.Configuration.csproj +24 -0
  17. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Credentials/NuGet.Credentials.csproj +20 -0
  18. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.DependencyResolver.Core/NuGet.DependencyResolver.Core.csproj +22 -0
  19. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Frameworks/NuGet.Frameworks.csproj +17 -0
  20. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.LibraryModel/NuGet.LibraryModel.csproj +17 -0
  21. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.PackageManagement/NuGet.PackageManagement.csproj +27 -0
  22. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Packaging/NuGet.Packaging.csproj +28 -0
  23. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.ProjectModel/NuGet.ProjectModel.csproj +20 -0
  24. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Protocol/NuGet.Protocol.csproj +21 -0
  25. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Resolver/NuGet.Resolver.csproj +20 -0
  26. data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Versioning/NuGet.Versioning.csproj +17 -0
  27. data/helpers/lib/NuGetUpdater/NuGetProjects/README.md +1 -0
  28. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/FrameworkCheckCommand.cs +35 -0
  29. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +43 -0
  30. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/NuGetUpdater.Cli.csproj +20 -0
  31. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +31 -0
  32. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.FrameworkCheck.cs +42 -0
  33. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +323 -0
  34. data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/NuGetUpdater.Cli.Test.csproj +24 -0
  35. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Dependency.cs +3 -0
  36. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyType.cs +12 -0
  37. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/BuildFile.cs +97 -0
  38. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/DotNetToolsJsonBuildFile.cs +24 -0
  39. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +25 -0
  40. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +32 -0
  41. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/PackagesConfigBuildFile.cs +31 -0
  42. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/ProjectBuildFile.cs +94 -0
  43. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/XmlBuildFile.cs +14 -0
  44. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/CompatabilityChecker.cs +39 -0
  45. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/FrameworkCompatibilityService.cs +73 -0
  46. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/SupportedFrameworks.cs +146 -0
  47. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/NuGetUpdater.Core.csproj +27 -0
  48. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs +316 -0
  49. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectResolver.cs +87 -0
  50. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/ConfigurationFile.cs +3 -0
  51. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +66 -0
  52. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +48 -0
  53. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +172 -0
  54. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SdkPackageUpdater.cs +498 -0
  55. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateResult.cs +7 -0
  56. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +105 -0
  57. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/JsonHelper.cs +222 -0
  58. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/Logger.cs +24 -0
  59. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +443 -0
  60. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/NuGetHelper.cs +15 -0
  61. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +69 -0
  62. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProcessExtensions.cs +66 -0
  63. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/XmlExtensions.cs +124 -0
  64. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/DotNetToolsJsonBuildFileTests.cs +52 -0
  65. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +63 -0
  66. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/PackagesConfigBuildFileTests.cs +63 -0
  67. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/ProjectBuildFileTests.cs +154 -0
  68. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/CompatibilityCheckerFacts.cs +64 -0
  69. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/FrameworkCompatibilityServiceFacts.cs +122 -0
  70. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/SupportedFrameworkFacts.cs +68 -0
  71. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/NuGetUpdater.Core.Test.csproj +23 -0
  72. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TemporaryDirectory.cs +36 -0
  73. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestExtensions.cs +15 -0
  74. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +79 -0
  75. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorker.DirsProj.cs +201 -0
  76. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +147 -0
  77. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DotNetTools.cs +225 -0
  78. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +217 -0
  79. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Mixed.cs +94 -0
  80. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +938 -0
  81. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Sdk.cs +2177 -0
  82. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/JsonHelperTests.cs +239 -0
  83. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +394 -0
  84. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterHelperTests.cs +179 -0
  85. data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterTests.cs +238 -0
  86. data/helpers/lib/NuGetUpdater/NuGetUpdater.sln +152 -0
  87. data/helpers/lib/NuGetUpdater/xunit.runner.json +4 -0
  88. data/lib/dependabot/nuget/metadata_finder.rb +4 -4
  89. metadata +91 -5
@@ -0,0 +1,15 @@
1
+ using System.IO;
2
+
3
+ namespace NuGetUpdater.Core;
4
+
5
+ internal static class NuGetHelper
6
+ {
7
+ internal const string PackagesConfigFileName = "packages.config";
8
+
9
+ public static bool HasProjectConfigFile(string projectPath)
10
+ {
11
+ var projectDirectory = Path.GetDirectoryName(projectPath);
12
+ var packagesConfigPath = PathHelper.JoinPath(projectDirectory, PackagesConfigFileName);
13
+ return File.Exists(packagesConfigPath);
14
+ }
15
+ }
@@ -0,0 +1,69 @@
1
+ using System.Collections.Generic;
2
+ using System.IO;
3
+ using System.Linq;
4
+
5
+ namespace NuGetUpdater.Core;
6
+
7
+ internal static class PathHelper
8
+ {
9
+ private static readonly EnumerationOptions _caseInsensitiveEnumerationOptions = new()
10
+ {
11
+ MatchCasing = MatchCasing.CaseInsensitive,
12
+ };
13
+ private static readonly EnumerationOptions _caseSensitiveEnumerationOptions = new()
14
+ {
15
+ MatchCasing = MatchCasing.CaseSensitive,
16
+ };
17
+
18
+ public static string JoinPath(string? path1, string path2)
19
+ {
20
+ // don't root out the second path
21
+ if (path2.StartsWith('/'))
22
+ {
23
+ path2 = path2[1..];
24
+ }
25
+
26
+ return path1 is null
27
+ ? path2
28
+ : Path.Combine(path1, path2);
29
+ }
30
+
31
+ public static string NormalizePathToUnix(this string path) => path.Replace("\\", "/");
32
+
33
+ public static string GetFullPathFromRelative(string rootPath, string relativePath)
34
+ => Path.GetFullPath(JoinPath(rootPath, relativePath.NormalizePathToUnix()));
35
+
36
+ /// <summary>
37
+ /// Check in every directory from <paramref name="initialPath"/> up to <paramref name="rootPath"/> for the file specified in <paramref name="fileName"/>.
38
+ /// </summary>
39
+ /// <returns>The path of the found file or null.</returns>
40
+ public static string? GetFileInDirectoryOrParent(string initialPath, string rootPath, string fileName, bool caseSensitive = true)
41
+ {
42
+ var candidatePaths = new List<string>();
43
+ var rootDirectory = new DirectoryInfo(rootPath);
44
+ var candidateDirectory = new DirectoryInfo(initialPath);
45
+ while (candidateDirectory.FullName != rootDirectory.FullName)
46
+ {
47
+ candidatePaths.Add(candidateDirectory.FullName);
48
+ candidateDirectory = candidateDirectory.Parent;
49
+ if (candidateDirectory is null)
50
+ {
51
+ break;
52
+ }
53
+ }
54
+
55
+ candidatePaths.Add(rootPath);
56
+
57
+ foreach (var candidatePath in candidatePaths)
58
+ {
59
+ var files = Directory.EnumerateFiles(candidatePath, fileName, caseSensitive ? _caseSensitiveEnumerationOptions : _caseInsensitiveEnumerationOptions);
60
+
61
+ if (files.Any())
62
+ {
63
+ return files.First();
64
+ }
65
+ }
66
+
67
+ return null;
68
+ }
69
+ }
@@ -0,0 +1,66 @@
1
+ using System;
2
+ using System.Diagnostics;
3
+ using System.Text;
4
+ using System.Threading.Tasks;
5
+
6
+ namespace NuGetUpdater.Core;
7
+
8
+ public static class ProcessEx
9
+ {
10
+ public static Task<(int ExitCode, string Output, string Error)> RunAsync(string fileName, string arguments = "", string? workingDirectory = null)
11
+ {
12
+ var tcs = new TaskCompletionSource<(int, string, string)>();
13
+
14
+ var process = new Process
15
+ {
16
+ StartInfo =
17
+ {
18
+ FileName = fileName,
19
+ Arguments = arguments,
20
+ UseShellExecute = false, // required to redirect output
21
+ RedirectStandardOutput = true,
22
+ RedirectStandardError = true,
23
+ },
24
+ EnableRaisingEvents = true
25
+ };
26
+
27
+ if (workingDirectory is not null)
28
+ {
29
+ process.StartInfo.WorkingDirectory = workingDirectory;
30
+ }
31
+
32
+ var stdout = new StringBuilder();
33
+ var stderr = new StringBuilder();
34
+
35
+ process.OutputDataReceived += (_, e) => stdout.AppendLine(e.Data);
36
+ process.ErrorDataReceived += (_, e) => stderr.AppendLine(e.Data);
37
+
38
+ process.Exited += (sender, args) =>
39
+ {
40
+ tcs.TrySetResult((process.ExitCode, stdout.ToString(), stderr.ToString()));
41
+ process.Dispose();
42
+ };
43
+
44
+ #if DEBUG
45
+ // don't hang when running locally
46
+ var timeout = TimeSpan.FromSeconds(20);
47
+ Task.Delay(timeout).ContinueWith(_ =>
48
+ {
49
+ if (!tcs.Task.IsCompleted && !Debugger.IsAttached)
50
+ {
51
+ tcs.SetException(new Exception($"Process failed to exit after {timeout.TotalSeconds} seconds: {fileName} {arguments}\nstdout:\n{stdout}\n\nstderr:\n{stderr}"));
52
+ }
53
+ });
54
+ #endif
55
+
56
+ if (!process.Start())
57
+ {
58
+ throw new InvalidOperationException("Process failed to start");
59
+ }
60
+
61
+ process.BeginOutputReadLine();
62
+ process.BeginErrorReadLine();
63
+
64
+ return tcs.Task;
65
+ }
66
+ }
@@ -0,0 +1,124 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Linq;
4
+
5
+ using Microsoft.Language.Xml;
6
+
7
+ namespace NuGetUpdater.Core;
8
+
9
+ public static class XmlExtensions
10
+ {
11
+ public static string? GetAttributeOrSubElementValue(this IXmlElementSyntax element, string name, StringComparison comparisonType = StringComparison.Ordinal)
12
+ {
13
+ var attribute = element.GetAttribute(name, comparisonType);
14
+ if (attribute is not null)
15
+ {
16
+ return attribute.Value;
17
+ }
18
+
19
+ var subElement = element.GetElements(name, comparisonType).FirstOrDefault();
20
+ return subElement?.GetContentValue();
21
+ }
22
+
23
+ public static IEnumerable<IXmlElementSyntax> GetElements(this IXmlElementSyntax element, string name, StringComparison comparisonType = StringComparison.Ordinal)
24
+ {
25
+ return element.Elements.Where(a => a.Name.Equals(name, comparisonType));
26
+ }
27
+
28
+ public static XmlAttributeSyntax? GetAttribute(this IXmlElementSyntax element, string name, StringComparison comparisonType)
29
+ {
30
+ return element.Attributes.FirstOrDefault(a => a.Name.Equals(name, comparisonType));
31
+ }
32
+
33
+ public static string GetAttributeValue(this IXmlElementSyntax element, string name, StringComparison comparisonType)
34
+ {
35
+ return element.Attributes.First(a => a.Name.Equals(name, comparisonType)).Value;
36
+ }
37
+
38
+ public static XmlAttributeSyntax? GetAttributeCaseInsensitive(this IXmlElementSyntax xml, string name) => GetAttribute(xml, name, StringComparison.OrdinalIgnoreCase);
39
+
40
+ public static string? GetAttributeValueCaseInsensitive(this IXmlElementSyntax xml, string name) => xml.GetAttributeCaseInsensitive(name)?.Value;
41
+
42
+ public static IXmlElementSyntax WithChildElement(this IXmlElementSyntax parent, string name)
43
+ {
44
+ var element = CreateOpenCloseXmlElementSyntax(name);
45
+ return parent.AddChild(element);
46
+ }
47
+
48
+ public static IXmlElementSyntax WithEmptyChildElement(this IXmlElementSyntax parent, string name)
49
+ {
50
+ var element = CreateSingleLineXmlElementSyntax(name);
51
+ return parent.AddChild(element);
52
+ }
53
+
54
+ public static IXmlElementSyntax WithContent(this IXmlElementSyntax element, string text)
55
+ {
56
+ var textSyntax = SyntaxFactory.XmlText(SyntaxFactory.Token(null, SyntaxKind.XmlTextLiteralToken, null, text));
57
+ return element.WithContent(SyntaxFactory.SingletonList(textSyntax));
58
+ }
59
+
60
+ public static IXmlElementSyntax WithAttribute(this IXmlElementSyntax parent, string name, string value)
61
+ {
62
+ var singleSpanceTrivia = SyntaxFactory.WhitespaceTrivia(" ");
63
+
64
+ return parent.AddAttribute(SyntaxFactory.XmlAttribute(
65
+ SyntaxFactory.XmlName(null, SyntaxFactory.XmlNameToken(name, null, null)),
66
+ SyntaxFactory.Punctuation(SyntaxKind.EqualsToken, "=", null, null),
67
+ SyntaxFactory.XmlString(
68
+ SyntaxFactory.Punctuation(SyntaxKind.SingleQuoteToken, "\"", null, null),
69
+ SyntaxFactory.XmlTextLiteralToken(value, null, null),
70
+ SyntaxFactory.Punctuation(SyntaxKind.SingleQuoteToken, "\"", null, singleSpanceTrivia))));
71
+ }
72
+
73
+ public static XmlElementSyntax CreateOpenCloseXmlElementSyntax(string name, int indentation = 2, bool spaces = true)
74
+ {
75
+ var leadingTrivia = SyntaxFactory.WhitespaceTrivia(new string(' ', indentation));
76
+ return CreateOpenCloseXmlElementSyntax(name, new SyntaxList<SyntaxNode>(leadingTrivia));
77
+ }
78
+
79
+ public static XmlElementSyntax CreateOpenCloseXmlElementSyntax(string name, SyntaxList<SyntaxNode> leadingTrivia)
80
+ {
81
+ var newlineTrivia = SyntaxFactory.WhitespaceTrivia(Environment.NewLine);
82
+
83
+ return SyntaxFactory.XmlElement(
84
+ SyntaxFactory.XmlElementStartTag(
85
+ SyntaxFactory.Punctuation(SyntaxKind.LessThanToken, "<", leadingTrivia, default),
86
+ SyntaxFactory.XmlName(null, SyntaxFactory.XmlNameToken(name, null, null)),
87
+ new SyntaxList<XmlAttributeSyntax>(),
88
+ SyntaxFactory.Punctuation(SyntaxKind.GreaterThanToken, ">", null, newlineTrivia)),
89
+ new SyntaxList<SyntaxNode>(),
90
+ SyntaxFactory.XmlElementEndTag(
91
+ SyntaxFactory.Punctuation(SyntaxKind.LessThanSlashToken, "</", leadingTrivia, default),
92
+ SyntaxFactory.XmlName(null, SyntaxFactory.XmlNameToken(name, null, null)),
93
+ SyntaxFactory.Punctuation(SyntaxKind.GreaterThanToken, ">", null, null)));
94
+ }
95
+
96
+ public static XmlEmptyElementSyntax CreateSingleLineXmlElementSyntax(string name, int indentation = 2, bool spaces = true)
97
+ {
98
+ var leadingTrivia = SyntaxFactory.WhitespaceTrivia(new string(' ', indentation));
99
+ var followingTrivia = SyntaxFactory.WhitespaceTrivia(Environment.NewLine);
100
+
101
+ return CreateSingleLineXmlElementSyntax(name, new SyntaxList<SyntaxNode>(leadingTrivia), new SyntaxList<SyntaxNode>(followingTrivia));
102
+ }
103
+
104
+ public static XmlEmptyElementSyntax CreateSingleLineXmlElementSyntax(string name, SyntaxList<SyntaxNode> leadingTrivia, SyntaxList<SyntaxNode> trailingTrivia = default)
105
+ {
106
+ var singleSpanceTrivia = SyntaxFactory.WhitespaceTrivia(" ");
107
+
108
+ return SyntaxFactory.XmlEmptyElement(
109
+ SyntaxFactory.Punctuation(SyntaxKind.LessThanToken, "<", leadingTrivia, default),
110
+ SyntaxFactory.XmlName(null, SyntaxFactory.XmlNameToken(name, null, singleSpanceTrivia)),
111
+ attributes: new SyntaxList<SyntaxNode>(),
112
+ SyntaxFactory.Punctuation(SyntaxKind.SlashGreaterThanToken, "/>", default, trailingTrivia));
113
+ }
114
+
115
+ public static IXmlElementSyntax ReplaceAttribute(this IXmlElementSyntax element, XmlAttributeSyntax oldAttribute, XmlAttributeSyntax newAttribute)
116
+ {
117
+ return element.WithAttributes(element.AttributesNode.Replace(oldAttribute, newAttribute));
118
+ }
119
+
120
+ public static IXmlElementSyntax ReplaceChildElement(this IXmlElementSyntax element, IXmlElementSyntax oldChildElement, IXmlElementSyntax newChildElement)
121
+ {
122
+ return element.WithContent(element.Content.Replace(oldChildElement.AsNode, newChildElement.AsNode));
123
+ }
124
+ }
@@ -0,0 +1,52 @@
1
+ using System.Collections.Generic;
2
+ using System.Diagnostics.CodeAnalysis;
3
+
4
+ using Xunit;
5
+
6
+ namespace NuGetUpdater.Core.Test.Files;
7
+
8
+ public class DotnetToolsJsonBuildFileTests
9
+ {
10
+ [StringSyntax(StringSyntaxAttribute.Json)]
11
+ const string DotnetToolsJson = """
12
+ {
13
+ "version": 1,
14
+ "isRoot": true,
15
+ "tools": {
16
+ "microsoft.botsay": {
17
+ "version": "1.0.0",
18
+ "commands": [
19
+ "botsay"
20
+ ]
21
+ },
22
+ "dotnetsay": {
23
+ "version": "2.1.3",
24
+ "commands": [
25
+ "dotnetsay"
26
+ ]
27
+ }
28
+ }
29
+ }
30
+ """;
31
+
32
+ private static DotNetToolsJsonBuildFile GetBuildFile() => new(
33
+ repoRootPath: "/",
34
+ path: "/.config/dotnet-tools.json",
35
+ contents: DotnetToolsJson);
36
+
37
+ [Fact]
38
+ public void GetDependencies_ReturnsDependencies()
39
+ {
40
+ var expectedDependencies = new List<Dependency>
41
+ {
42
+ new("microsoft.botsay", "1.0.0", DependencyType.DotNetTool),
43
+ new("dotnetsay", "2.1.3", DependencyType.DotNetTool)
44
+ };
45
+
46
+ var buildFile = GetBuildFile();
47
+
48
+ var dependencies = buildFile.GetDependencies();
49
+
50
+ Assert.Equal(expectedDependencies, dependencies);
51
+ }
52
+ }
@@ -0,0 +1,63 @@
1
+ using System.Collections.Generic;
2
+ using System.Diagnostics.CodeAnalysis;
3
+ using System.Linq;
4
+
5
+ using Xunit;
6
+
7
+ namespace NuGetUpdater.Core.Test.Files;
8
+
9
+ public class GlobalJsonBuildFileTests
10
+ {
11
+ [StringSyntax(StringSyntaxAttribute.Json)]
12
+ const string GlobalJson = """
13
+ {
14
+ "sdk": {
15
+ "version": "6.0.405",
16
+ "rollForward": "latestPatch"
17
+ },
18
+ "msbuild-sdks": {
19
+ "My.Custom.Sdk": "5.0.0",
20
+ "My.Other.Sdk": "1.0.0-beta"
21
+ }
22
+ }
23
+ """;
24
+
25
+ [StringSyntax(StringSyntaxAttribute.Json)]
26
+ const string EmptyGlobalJson = """
27
+ {
28
+ }
29
+ """;
30
+
31
+ private static GlobalJsonBuildFile GetBuildFile(string contents) => new(
32
+ repoRootPath: "/",
33
+ path: "/global.json",
34
+ contents: contents);
35
+
36
+ [Fact]
37
+ public void GlobalJson_GetDependencies_ReturnsDependencies()
38
+ {
39
+ var expectedDependencies = new List<Dependency>
40
+ {
41
+ new("My.Custom.Sdk", "5.0.0", DependencyType.MSBuildSdk),
42
+ new("My.Other.Sdk", "1.0.0-beta", DependencyType.MSBuildSdk)
43
+ };
44
+
45
+ var buildFile = GetBuildFile(GlobalJson);
46
+
47
+ var dependencies = buildFile.GetDependencies();
48
+
49
+ Assert.Equal(expectedDependencies, dependencies);
50
+ }
51
+
52
+ [Fact]
53
+ public void EmptyGlobalJson_GetDependencies_ReturnsNoDependencies()
54
+ {
55
+ var expectedDependencies = Enumerable.Empty<Dependency>();
56
+
57
+ var buildFile = GetBuildFile(EmptyGlobalJson);
58
+
59
+ var dependencies = buildFile.GetDependencies();
60
+
61
+ Assert.Equal(expectedDependencies, dependencies);
62
+ }
63
+ }
@@ -0,0 +1,63 @@
1
+ using System.Collections.Generic;
2
+ using System.Diagnostics.CodeAnalysis;
3
+ using System.Linq;
4
+
5
+ using Microsoft.Language.Xml;
6
+
7
+ using Xunit;
8
+
9
+ namespace NuGetUpdater.Core.Test.Files;
10
+
11
+ public class PackagesConfigBuildFileTests
12
+ {
13
+ [StringSyntax(StringSyntaxAttribute.Xml)]
14
+ const string PackagesConfig = """
15
+ <?xml version="1.0" encoding="utf-8"?>
16
+ <packages>
17
+ <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net46" />
18
+ <package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net46" developmentDependency="true" />
19
+ <package id="Newtonsoft.Json" version="8.0.3" allowedVersions="[8,10)" targetFramework="net46" />
20
+ </packages>
21
+ """;
22
+
23
+ [StringSyntax(StringSyntaxAttribute.Xml)]
24
+ const string EmptyPackagesConfig = """
25
+ <?xml version="1.0" encoding="utf-8"?>
26
+ <packages>
27
+ </packages>
28
+ """;
29
+
30
+ private static PackagesConfigBuildFile GetBuildFile(string contents) => new(
31
+ repoRootPath: "/",
32
+ path: "/packages.config",
33
+ contents: Parser.ParseText(contents));
34
+
35
+ [Fact]
36
+ public void PackagesConfig_GetDependencies_ReturnsDependencies()
37
+ {
38
+ var expectedDependencies = new List<Dependency>
39
+ {
40
+ new("Microsoft.CodeDom.Providers.DotNetCompilerPlatform", "1.0.0", DependencyType.PackageConfig),
41
+ new("Microsoft.Net.Compilers", "1.0.0", DependencyType.PackageConfig, true),
42
+ new("Newtonsoft.Json", "8.0.3", DependencyType.PackageConfig)
43
+ };
44
+
45
+ var buildFile = GetBuildFile(PackagesConfig);
46
+
47
+ var dependencies = buildFile.GetDependencies();
48
+
49
+ Assert.Equal(expectedDependencies, dependencies);
50
+ }
51
+
52
+ [Fact]
53
+ public void EmptyPackagesConfig_GetDependencies_ReturnsNoDependencies()
54
+ {
55
+ var expectedDependencies = Enumerable.Empty<Dependency>();
56
+
57
+ var buildFile = GetBuildFile(EmptyPackagesConfig);
58
+
59
+ var dependencies = buildFile.GetDependencies();
60
+
61
+ Assert.Equal(expectedDependencies, dependencies);
62
+ }
63
+ }
@@ -0,0 +1,154 @@
1
+ using System.Collections.Generic;
2
+ using System.Diagnostics.CodeAnalysis;
3
+ using System.Linq;
4
+ using System.Text.RegularExpressions;
5
+
6
+ using Microsoft.Language.Xml;
7
+
8
+ using Xunit;
9
+
10
+ namespace NuGetUpdater.Core.Test.Files;
11
+
12
+ public class ProjectBuildFileTests
13
+ {
14
+ [StringSyntax(StringSyntaxAttribute.Xml)]
15
+ const string ProjectCsProj = """
16
+ <Project Sdk="Microsoft.NET.Sdk">
17
+ <PropertyGroup>
18
+ <OutputType>Exe</OutputType>
19
+ <TargetFramework>net7.0</TargetFramework>
20
+ </PropertyGroup>
21
+ <ItemGroup>
22
+ <ProjectReference Include=".\Library\Library.csproj" />
23
+ </ItemGroup>
24
+ <ItemGroup>
25
+ <PackageReference Include="GuiLabs.Language.Xml" Version="1.2.60" />
26
+ <PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
27
+ <PackageReference Update="Newtonsoft.Json" VersionOverride="13.0.3" />
28
+ </ItemGroup>
29
+ </Project>
30
+ """;
31
+
32
+ [StringSyntax(StringSyntaxAttribute.Xml)]
33
+ const string EmptyProject = """
34
+ <Project>
35
+ </Project>
36
+ """;
37
+
38
+ [StringSyntax(StringSyntaxAttribute.Xml)]
39
+ const string DirectoryPackagesProps = """
40
+ <Project>
41
+ <PropertyGroup>
42
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
43
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
44
+ </PropertyGroup>
45
+ <ItemGroup>
46
+ <GlobalPackageReference Include="Microsoft.CodeAnalysis.Common" Version="$(RoslynVersion)" />
47
+ <PackageVersion Include="Newtonsoft.Json" VersionOverride="13.0.1" />
48
+ </ItemGroup>
49
+ </Project>
50
+ """;
51
+
52
+ private static ProjectBuildFile GetBuildFile(string contents, string filename) => new(
53
+ repoRootPath: "/",
54
+ path: $"/{filename}",
55
+ contents: Parser.ParseText(contents));
56
+
57
+ [Fact]
58
+ public void ProjectCsProj_GetDependencies_ReturnsDependencies()
59
+ {
60
+ var expectedDependencies = new List<Dependency>
61
+ {
62
+ new("GuiLabs.Language.Xml", "1.2.60", DependencyType.PackageReference),
63
+ new("Microsoft.CodeAnalysis.CSharp", null, DependencyType.PackageReference),
64
+ new("Newtonsoft.Json", "13.0.3", DependencyType.PackageReference, IsOverride: true)
65
+ };
66
+
67
+ var buildFile = GetBuildFile(ProjectCsProj, "Project.csproj");
68
+
69
+ var dependencies = buildFile.GetDependencies();
70
+
71
+ Assert.Equal(expectedDependencies, dependencies);
72
+ }
73
+
74
+ [Fact]
75
+ public void ProjectCsProj_ReferencedProjectPaths_ReturnsPaths()
76
+ {
77
+ var expectedReferencedProjectPaths = new List<string>
78
+ {
79
+ "/Library/Library.csproj"
80
+ };
81
+
82
+ var buildFile = GetBuildFile(ProjectCsProj, "Project.csproj");
83
+
84
+ var referencedProjectPaths = buildFile.GetReferencedProjectPaths()
85
+ .Select(p => Regex.IsMatch(p, @"^[A-Z]:\\") ? "/" + p.Substring(@"C:\".Length) : p) // remove drive letter when testing on Windows
86
+ .Select(p => p.NormalizePathToUnix());
87
+
88
+ Assert.Equal(expectedReferencedProjectPaths, referencedProjectPaths);
89
+ }
90
+
91
+ [Fact]
92
+ public void DirectoryPackagesProps_GetDependencies_ReturnsDependencies()
93
+ {
94
+ var expectedDependencies = new List<Dependency>
95
+ {
96
+ new("Microsoft.CodeAnalysis.Common", "$(RoslynVersion)", DependencyType.GlobalPackageReference),
97
+ new("Newtonsoft.Json", "13.0.1", DependencyType.PackageVersion, IsOverride: true)
98
+ };
99
+
100
+ var buildFile = GetBuildFile(DirectoryPackagesProps, "Directory.Packages.props");
101
+
102
+ var dependencies = buildFile.GetDependencies();
103
+
104
+ Assert.Equal(expectedDependencies, dependencies);
105
+ }
106
+
107
+ [Fact]
108
+ public void DirectoryPackagesProps_Properties_ReturnsProperties()
109
+ {
110
+ var expectedProperties = new List<KeyValuePair<string, string>>
111
+ {
112
+ new("ManagePackageVersionsCentrally", "true"),
113
+ new("CentralPackageTransitivePinningEnabled", "true")
114
+ };
115
+
116
+ var buildFile = GetBuildFile(DirectoryPackagesProps, "Directory.Packages.props");
117
+
118
+ var properties = buildFile.GetProperties();
119
+
120
+ Assert.Equal(expectedProperties, properties);
121
+ }
122
+
123
+ [Fact]
124
+ public void EmptyProject_GetDependencies_ReturnsNoDependencies()
125
+ {
126
+ var expectedDependencies = Enumerable.Empty<Dependency>();
127
+
128
+ var buildFile = GetBuildFile(EmptyProject, "project.csproj");
129
+
130
+ var dependencies = buildFile.GetDependencies();
131
+
132
+ Assert.Equal(expectedDependencies, dependencies);
133
+ }
134
+
135
+ [Theory]
136
+ [InlineData( // no change made
137
+ @"<Project><ItemGroup><Reference><HintPath>path\to\file.dll</HintPath></Reference></ItemGroup></Project>",
138
+ @"<Project><ItemGroup><Reference><HintPath>path\to\file.dll</HintPath></Reference></ItemGroup></Project>"
139
+ )]
140
+ [InlineData( // change from `/` to `\`
141
+ "<Project><ItemGroup><Reference><HintPath>path/to/file.dll</HintPath></Reference></ItemGroup></Project>",
142
+ @"<Project><ItemGroup><Reference><HintPath>path\to\file.dll</HintPath></Reference></ItemGroup></Project>"
143
+ )]
144
+ [InlineData( // multiple changes made
145
+ "<Project><ItemGroup><Reference><HintPath>path1/to1/file1.dll</HintPath></Reference><Reference><HintPath>path2/to2/file2.dll</HintPath></Reference></ItemGroup></Project>",
146
+ @"<Project><ItemGroup><Reference><HintPath>path1\to1\file1.dll</HintPath></Reference><Reference><HintPath>path2\to2\file2.dll</HintPath></Reference></ItemGroup></Project>"
147
+ )]
148
+ public void ReferenceHintPathsCanBeNormalized(string originalXml, string expectedXml)
149
+ {
150
+ ProjectBuildFile? buildFile = GetBuildFile(originalXml, "project.csproj");
151
+ buildFile.NormalizeDirectorySeparatorsInProject();
152
+ Assert.Equal(expectedXml, buildFile.Contents.ToFullString());
153
+ }
154
+ }
@@ -0,0 +1,64 @@
1
+ using NuGetUpdater.Core.FrameworkChecker;
2
+
3
+ using Xunit;
4
+
5
+ namespace NuGetUpdater.Core.Test.FrameworkChecker;
6
+
7
+ public class CompatibilityCheckerFacts
8
+ {
9
+ [Theory]
10
+ [InlineData("net8.0", "net8.0")]
11
+ [InlineData("net8.0", "net7.0")]
12
+ [InlineData("net7.0", "net7.0")]
13
+ [InlineData("net7.0", "net6.0")]
14
+ [InlineData("net7.0", "net5.0")]
15
+ [InlineData("net7.0", "netcoreapp3.1")]
16
+ [InlineData("net7.0", "netstandard2.1")]
17
+ [InlineData("net7.0", "netstandard2.0")]
18
+ [InlineData("net7.0", "netstandard1.3")]
19
+ [InlineData("net4.8", "netstandard2.0")]
20
+ [InlineData("net4.8", "netstandard1.3")]
21
+ public void PackageContainsCompatibleFramework(string projectTfm, string packageTfm)
22
+ {
23
+ var result = CompatibilityChecker.IsCompatible(new[] { projectTfm }, new[] { packageTfm }, new Logger(verbose: true));
24
+
25
+ Assert.True(result);
26
+ }
27
+
28
+ [Theory]
29
+ [InlineData("net48", "netcoreapp3.1")]
30
+ [InlineData("net48", "netstandard2.1")]
31
+ [InlineData("net7.0", "net8.0")]
32
+ [InlineData("net6.0", "net7.0")]
33
+ [InlineData("net5.0", "net6.0")]
34
+ [InlineData("netcoreapp3.1", "net5.0")]
35
+ [InlineData("netstandard2.0", "netstandard2.1")]
36
+ [InlineData("netstandard1.3", "netstandard2.0")]
37
+ [InlineData("net7.0", "net48")]
38
+ public void PackageContainsIncompatibleFramework(string projectTfm, string packageTfm)
39
+ {
40
+ var result = CompatibilityChecker.IsCompatible(new[] { projectTfm }, new[] { packageTfm }, new Logger(verbose: true));
41
+
42
+ Assert.False(result);
43
+ }
44
+
45
+ [Theory]
46
+ [InlineData(new[] { "net8.0", "net7.0", "net472" }, new[] { "netstandard2.0" })]
47
+ [InlineData(new[] { "net8.0", "net7.0", "net472" }, new[] { "net5.0", "net461" })]
48
+ [InlineData(new[] { "net6.0", "net6.0-windows10.0.19041" }, new[] { "net6.0", ".NETStandard2.0" })]
49
+ public void PackageContainsCompatibleFrameworks(string[] projectTfms, string[] packageTfms)
50
+ {
51
+ var result = CompatibilityChecker.IsCompatible(projectTfms, packageTfms, new Logger(verbose: true));
52
+
53
+ Assert.True(result);
54
+ }
55
+
56
+ [Theory]
57
+ [InlineData(new[] { "net7.0", "net472" }, new[] { "net5.0" })]
58
+ public void PackageContainsIncompatibleFrameworks(string[] projectTfms, string[] packageTfms)
59
+ {
60
+ var result = CompatibilityChecker.IsCompatible(projectTfms, packageTfms, new Logger(verbose: true));
61
+
62
+ Assert.False(result);
63
+ }
64
+ }