Skip to content

Commit af9df1d

Browse files
authored
LockFile.GetTarget now uses LockFileTarget aliases to match the target, remove more project.json usage, simplify SpecValidationUtility API (#6992)
1 parent c5865f9 commit af9df1d

18 files changed

Lines changed: 79 additions & 468 deletions

File tree

src/NuGet.Core/NuGet.Commands/GlobalSuppressions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,10 @@
110110
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'Task<IReadOnlyList<RestoreResultPair>> RestoreRunner.RunWithoutCommit(IEnumerable<RestoreSummaryRequest> restoreRequests, RestoreArgs restoreContext)', validate parameter 'restoreContext' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.RestoreRunner.RunWithoutCommit(System.Collections.Generic.IEnumerable{NuGet.Commands.RestoreSummaryRequest},NuGet.Commands.RestoreArgs)~System.Threading.Tasks.Task{System.Collections.Generic.IReadOnlyList{NuGet.Commands.RestoreResultPair}}")]
111111
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'RestoreSummary.RestoreSummary(RestoreResult result, string inputPath, IEnumerable<string> configFiles, IEnumerable<SourceRepository> sourceRepositories, IEnumerable<RestoreLogMessage> errors)', validate parameter 'result' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.RestoreSummary.#ctor(NuGet.Commands.RestoreResult,System.String,System.Collections.Generic.IEnumerable{System.String},System.Collections.Generic.IEnumerable{NuGet.Protocol.Core.Types.SourceRepository},System.Collections.Generic.IEnumerable{NuGet.Common.RestoreLogMessage})")]
112112
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void RestoreSummary.Log(ILogger logger, IReadOnlyList<RestoreSummary> restoreSummaries, bool logErrors = false)', validate parameter 'logger' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.RestoreSummary.Log(NuGet.Common.ILogger,System.Collections.Generic.IReadOnlyList{NuGet.Commands.RestoreSummary},System.Boolean)")]
113-
[assembly: SuppressMessage("Build", "CA1801:Parameter log of method Create is never used. Remove the parameter or use it in the method body.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.RestoreTargetGraph.Create(NuGet.RuntimeModel.RuntimeGraph,System.Collections.Generic.IEnumerable{NuGet.DependencyResolver.GraphNode{NuGet.DependencyResolver.RemoteResolveResult}},NuGet.DependencyResolver.RemoteWalkContext,NuGet.Common.ILogger,System.String,NuGet.Frameworks.NuGetFramework,System.String)~NuGet.Commands.RestoreTargetGraph")]
114-
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'RestoreTargetGraph RestoreTargetGraph.Create(RuntimeGraph runtimeGraph, IEnumerable<GraphNode<RemoteResolveResult>> graphs, RemoteWalkContext context, ILogger log, System.String targetAlias, NuGetFramework framework, string runtimeIdentifier)', validate parameter 'graphs' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.RestoreTargetGraph.Create(NuGet.RuntimeModel.RuntimeGraph,System.Collections.Generic.IEnumerable{NuGet.DependencyResolver.GraphNode{NuGet.DependencyResolver.RemoteResolveResult}},NuGet.DependencyResolver.RemoteWalkContext,NuGet.Common.ILogger,System.String,NuGet.Frameworks.NuGetFramework,System.String)~NuGet.Commands.RestoreTargetGraph")]
115113
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'Task<int> SignCommandRunner.ExecuteCommandAsync(SignArgs signArgs)', validate parameter 'signArgs' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.SignCommandRunner.ExecuteCommandAsync(NuGet.Commands.SignArgs)~System.Threading.Tasks.Task{System.Int32}")]
116114
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'Task<int> SignCommandRunner.ExecuteCommandAsync(IEnumerable<string> packagesToSign, SignPackageRequest signPackageRequest, string timestamper, ILogger logger, string outputDirectory, bool overwrite, CancellationToken token)', validate parameter 'packagesToSign' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.SignCommandRunner.ExecuteCommandAsync(System.Collections.Generic.IEnumerable{System.String},NuGet.Packaging.Signing.SignPackageRequest,System.String,NuGet.Common.ILogger,System.String,System.Boolean,System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.Int32}")]
117115
[assembly: SuppressMessage("Build", "CA1822:Member ExecuteCommandAsync does not access instance data and can be marked as static (Shared in VisualBasic)", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.SignCommandRunner.ExecuteCommandAsync(System.Collections.Generic.IEnumerable{System.String},NuGet.Packaging.Signing.SignPackageRequest,System.String,NuGet.Common.ILogger,System.String,System.Boolean,System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.Int32}")]
118116
[assembly: SuppressMessage("Build", "CA1031:Modify 'ExecuteCommandAsync' to catch a more specific allowed exception type, or rethrow the exception.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.SignCommandRunner.ExecuteCommandAsync(System.Collections.Generic.IEnumerable{System.String},NuGet.Packaging.Signing.SignPackageRequest,System.String,NuGet.Common.ILogger,System.String,System.Boolean,System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.Int32}")]
119-
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void SpecValidationUtility.ValidateDependencySpec(DependencyGraphSpec spec, HashSet<string> projectsToSkip)', validate parameter 'projectsToSkip' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.SpecValidationUtility.ValidateDependencySpec(NuGet.ProjectModel.DependencyGraphSpec,System.Collections.Generic.HashSet{System.String})")]
120117
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'PackageSpec ToolRestoreUtility.GetSpec(string projectFilePath, string id, VersionRange versionRange, NuGetFramework framework, string packagesPath, IList<string> fallbackFolders, IList<PackageSource> sources, WarningProperties projectWideWarningProperties)', validate parameter 'framework' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.ToolRestoreUtility.GetSpec(System.String,System.String,NuGet.Versioning.VersionRange,NuGet.Frameworks.NuGetFramework,System.String,System.Collections.Generic.IList{System.String},System.Collections.Generic.IList{NuGet.Configuration.PackageSource},NuGet.ProjectModel.WarningProperties)~NuGet.ProjectModel.PackageSpec")]
121118
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'IReadOnlyList<RestoreSummaryRequest> ToolRestoreUtility.GetSubSetRequests(IEnumerable<RestoreSummaryRequest> requestSummaries)', validate parameter 'requestSummaries' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.ToolRestoreUtility.GetSubSetRequests(System.Collections.Generic.IEnumerable{NuGet.Commands.RestoreSummaryRequest})~System.Collections.Generic.IReadOnlyList{NuGet.Commands.RestoreSummaryRequest}")]
122119
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'LockFileTargetLibrary ToolRestoreUtility.GetToolTargetLibrary(LockFile toolLockFile, string toolId)', validate parameter 'toolLockFile' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.ToolRestoreUtility.GetToolTargetLibrary(NuGet.ProjectModel.LockFile,System.String)~NuGet.ProjectModel.LockFileTargetLibrary")]

src/NuGet.Core/NuGet.Commands/PublicAPI/net472/PublicAPI.Shipped.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,6 @@ static NuGet.Commands.Restore.Utility.PackageSpecFactory.GetPackageSpec(NuGet.Co
993993
~static NuGet.Commands.RestoreSpecException.Create(string message, System.Collections.Generic.IEnumerable<string> files, System.Exception innerException) -> NuGet.Commands.RestoreSpecException
994994
~static NuGet.Commands.RestoreSummary.Log(NuGet.Common.ILogger logger, System.Collections.Generic.IReadOnlyList<NuGet.Commands.RestoreSummary> restoreSummaries, bool logErrors = false) -> void
995995
~static NuGet.Commands.SpecValidationUtility.ValidateDependencySpec(NuGet.ProjectModel.DependencyGraphSpec spec) -> void
996-
~static NuGet.Commands.SpecValidationUtility.ValidateDependencySpec(NuGet.ProjectModel.DependencyGraphSpec spec, System.Collections.Generic.HashSet<string> projectsToSkip) -> void
997996
~static NuGet.Commands.SpecValidationUtility.ValidateDependencySpec(NuGet.ProjectModel.DependencyGraphSpec spec, System.Collections.Generic.HashSet<string> projectsToSkip, NuGet.Common.ILogger logger) -> void
998997
~static NuGet.Commands.SpecValidationUtility.ValidateProjectSpec(NuGet.ProjectModel.PackageSpec spec) -> void
999998
~static NuGet.Commands.ToolRestoreUtility.GetSpec(string projectFilePath, string id, NuGet.Versioning.VersionRange versionRange, NuGet.Frameworks.NuGetFramework framework, string packagesPath, System.Collections.Generic.IList<string> fallbackFolders, System.Collections.Generic.IList<NuGet.Configuration.PackageSource> sources, NuGet.ProjectModel.WarningProperties projectWideWarningProperties) -> NuGet.ProjectModel.PackageSpec

src/NuGet.Core/NuGet.Commands/PublicAPI/net8.0/PublicAPI.Shipped.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,6 @@ static NuGet.Commands.Restore.Utility.PackageSpecFactory.GetPackageSpec(NuGet.Co
992992
~static NuGet.Commands.RestoreSpecException.Create(string message, System.Collections.Generic.IEnumerable<string> files, System.Exception innerException) -> NuGet.Commands.RestoreSpecException
993993
~static NuGet.Commands.RestoreSummary.Log(NuGet.Common.ILogger logger, System.Collections.Generic.IReadOnlyList<NuGet.Commands.RestoreSummary> restoreSummaries, bool logErrors = false) -> void
994994
~static NuGet.Commands.SpecValidationUtility.ValidateDependencySpec(NuGet.ProjectModel.DependencyGraphSpec spec) -> void
995-
~static NuGet.Commands.SpecValidationUtility.ValidateDependencySpec(NuGet.ProjectModel.DependencyGraphSpec spec, System.Collections.Generic.HashSet<string> projectsToSkip) -> void
996995
~static NuGet.Commands.SpecValidationUtility.ValidateDependencySpec(NuGet.ProjectModel.DependencyGraphSpec spec, System.Collections.Generic.HashSet<string> projectsToSkip, NuGet.Common.ILogger logger) -> void
997996
~static NuGet.Commands.SpecValidationUtility.ValidateProjectSpec(NuGet.ProjectModel.PackageSpec spec) -> void
998997
~static NuGet.Commands.ToolRestoreUtility.GetSpec(string projectFilePath, string id, NuGet.Versioning.VersionRange versionRange, NuGet.Frameworks.NuGetFramework framework, string packagesPath, System.Collections.Generic.IList<string> fallbackFolders, System.Collections.Generic.IList<NuGet.Configuration.PackageSource> sources, NuGet.ProjectModel.WarningProperties projectWideWarningProperties) -> NuGet.ProjectModel.PackageSpec

src/NuGet.Core/NuGet.Commands/RestoreCommand/CompatibilityChecker.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ private CompatibilityData GetCompatibilityData(RestoreTargetGraph graph, Library
373373
for (int i = 0; i < _lockFile.Targets.Count; ++i)
374374
{
375375
var target = _lockFile.Targets[i];
376-
if (Equals(target.TargetFramework, graph.Framework) && string.Equals(target.RuntimeIdentifier, graph.RuntimeIdentifier, StringComparison.Ordinal))
376+
// When comparing the target alias, a null targetAlias means that we have a support added and as such the alias won't be available.
377+
if (Equals(target.TargetFramework, graph.Framework) && (target.TargetAlias == null || Equals(target.TargetAlias, graph.TargetAlias)) && string.Equals(target.RuntimeIdentifier, graph.RuntimeIdentifier, StringComparison.Ordinal))
377378
{
378379
for (int j = 0; j < target.Libraries.Count; ++j)
379380
{

src/NuGet.Core/NuGet.Commands/RestoreCommand/ProjectRestoreCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ await walker.WalkAsync(
296296
await _logger.LogAsync(LogLevel.Verbose, string.Format(CultureInfo.CurrentCulture, Strings.Log_ResolvingConflicts, name));
297297

298298
// Flatten and create the RestoreTargetGraph to hold the packages
299-
return RestoreTargetGraph.Create(runtimeGraph, graphs, context, _logger, targetAlias, framework, runtimeIdentifier);
299+
return RestoreTargetGraph.Create(runtimeGraph, graphs, context, targetAlias, framework, runtimeIdentifier);
300300
}
301301

302302
internal async Task<bool> ResolutionSucceeded(IEnumerable<RestoreTargetGraph> graphs, IList<DownloadDependencyResolutionResult> downloadDependencyResults, RemoteWalkContext context, CancellationToken token)

src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ private async Task<EvaluateLockFileResult>
612612
graphs = new(frameworkRuntimePairs.Count);
613613
for (var i = 0; i < frameworkRuntimePairs.Count; i++)
614614
{
615-
var restoreTargetGraph = RestoreTargetGraph.Create(_request.Project.RuntimeGraph, Enumerable.Empty<GraphNode<RemoteResolveResult>>(), contextForProject, _logger, frameworkRuntimePairs[i].TargetAlias, frameworkRuntimePairs[i].Framework, frameworkRuntimePairs[i].RuntimeIdentifier);
615+
var restoreTargetGraph = RestoreTargetGraph.Create(_request.Project.RuntimeGraph, Enumerable.Empty<GraphNode<RemoteResolveResult>>(), contextForProject, frameworkRuntimePairs[i].TargetAlias, frameworkRuntimePairs[i].Framework, frameworkRuntimePairs[i].RuntimeIdentifier);
616616
graphs.Add(restoreTargetGraph);
617617
}
618618
}
@@ -1751,7 +1751,7 @@ private static async Task<IList<CompatibilityCheckResult>> VerifyCompatibilityAs
17511751
// in order to avoid missing target errors from the SDK build tasks and ensure that NuGet errors don't get cleared.
17521752
foreach (FrameworkRuntimeDefinition frameworkRuntimePair in CreateFrameworkRuntimeDefinitions(_request.Project, RequestRuntimeUtility.GetRestoreRuntimes(_request)))
17531753
{
1754-
allGraphs.Add(RestoreTargetGraph.Create(_request.Project.RuntimeGraph, Enumerable.Empty<GraphNode<RemoteResolveResult>>(), context, _logger, frameworkRuntimePair.TargetAlias, frameworkRuntimePair.Framework, frameworkRuntimePair.RuntimeIdentifier));
1754+
allGraphs.Add(RestoreTargetGraph.Create(_request.Project.RuntimeGraph, Enumerable.Empty<GraphNode<RemoteResolveResult>>(), context, frameworkRuntimePair.TargetAlias, frameworkRuntimePair.Framework, frameworkRuntimePair.RuntimeIdentifier));
17551755
}
17561756
}
17571757

@@ -1907,7 +1907,7 @@ private static async Task<IList<CompatibilityCheckResult>> VerifyCompatibilityAs
19071907
// in order to avoid missing target errors from the SDK build tasks and ensure that NuGet errors don't get cleared.
19081908
foreach (FrameworkRuntimeDefinition frameworkRuntimePair in CreateFrameworkRuntimeDefinitions(_request.Project, RequestRuntimeUtility.GetRestoreRuntimes(_request)))
19091909
{
1910-
graphs.Add(RestoreTargetGraph.Create(_request.Project.RuntimeGraph, Enumerable.Empty<GraphNode<RemoteResolveResult>>(), context, _logger, frameworkRuntimePair.TargetAlias, frameworkRuntimePair.Framework, frameworkRuntimePair.RuntimeIdentifier));
1910+
graphs.Add(RestoreTargetGraph.Create(_request.Project.RuntimeGraph, Enumerable.Empty<GraphNode<RemoteResolveResult>>(), context, frameworkRuntimePair.TargetAlias, frameworkRuntimePair.Framework, frameworkRuntimePair.RuntimeIdentifier));
19111911
}
19121912
}
19131913

src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreTargetGraph.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using System.Globalization;
1010
using System.Linq;
1111
using NuGet.Client;
12-
using NuGet.Common;
1312
using NuGet.DependencyResolver;
1413
using NuGet.Frameworks;
1514
using NuGet.LibraryModel;
@@ -110,16 +109,10 @@ internal static string GetTargetGraphName(string targetAlias, string runtimeIden
110109
}
111110
}
112111

113-
internal static RestoreTargetGraph Create(IEnumerable<GraphNode<RemoteResolveResult>> graphs, RemoteWalkContext context, ILogger logger, string targetAlias, NuGetFramework framework)
114-
{
115-
return Create(RuntimeGraph.Empty, graphs, context, logger, targetAlias, framework, runtimeIdentifier: null);
116-
}
117-
118112
internal static RestoreTargetGraph Create(
119113
RuntimeGraph runtimeGraph,
120114
IEnumerable<GraphNode<RemoteResolveResult>> graphs,
121115
RemoteWalkContext context,
122-
ILogger log,
123116
string targetAlias,
124117
NuGetFramework framework,
125118
string runtimeIdentifier)

0 commit comments

Comments
 (0)