Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider AssetTargetFallback when selecting transitive project/package dependencies #4372

Merged
merged 6 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
[assembly: SuppressMessage("Build", "CA1308:In method 'LogInternal', replace the call to 'ToLowerInvariant' with 'ToUpperInvariant'.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.CommandOutputLogger.LogInternal(NuGet.Common.LogLevel,System.String)")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void CommandOutputLogger.LogInternal(LogLevel logLevel, string message)', validate parameter 'message' 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.CommandLine.XPlat.CommandOutputLogger.LogInternal(NuGet.Common.LogLevel,System.String)")]
[assembly: SuppressMessage("Build", "CA1307:The behavior of 'string.IndexOf(char)' could vary based on the current user's locale settings. Replace this call in 'NuGet.CommandLine.XPlat.CommandOutputLogger.LogInternal(NuGet.Common.LogLevel, string)' with a call to 'string.IndexOf(char, System.StringComparison)'.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.CommandOutputLogger.LogInternal(NuGet.Common.LogLevel,System.String)")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void ListPackageCommand.Register(CommandLineApplication app, Func<ILogger> getLogger, Func<IListPackageCommandRunner> getCommandRunner)', validate parameter 'app' 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.CommandLine.XPlat.ListPackageCommand.Register(Microsoft.Extensions.CommandLineUtils.CommandLineApplication,System.Func{NuGet.Common.ILogger},System.Func{NuGet.CommandLine.XPlat.IListPackageCommandRunner})")]
[assembly: SuppressMessage("Build", "CA1822:Member AddPackagesToDict does not access instance data and can be marked as static (Shared in VisualBasic)", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.ListPackageCommandRunner.AddPackagesToDict(System.Collections.Generic.IEnumerable{NuGet.CommandLine.XPlat.FrameworkPackages},System.Collections.Generic.Dictionary{System.String,System.Collections.Generic.IList{NuGet.Protocol.Core.Types.IPackageSearchMetadata}})")]
[assembly: SuppressMessage("Build", "CA1307:The behavior of 'string.Equals(string)' could vary based on the current user's locale settings. Replace this call in 'NuGet.CommandLine.XPlat.ListPackageCommandRunner.ExecuteCommandAsync(NuGet.CommandLine.XPlat.ListPackageArgs)' with a call to 'string.Equals(string, System.StringComparison)'.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.ListPackageCommandRunner.ExecuteCommandAsync(NuGet.CommandLine.XPlat.ListPackageArgs)~System.Threading.Tasks.Task")]
[assembly: SuppressMessage("Build", "CA1305:The behavior of 'string.Format(string, object)' could vary based on the current user's locale settings. Replace this call in 'ListPackageCommandRunner.ExecuteCommandAsync(ListPackageArgs)' with a call to 'string.Format(IFormatProvider, string, params object[])'.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.ListPackageCommandRunner.ExecuteCommandAsync(NuGet.CommandLine.XPlat.ListPackageArgs)~System.Threading.Tasks.Task")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'Task ListPackageCommandRunner.ExecuteCommandAsync(ListPackageArgs listPackageArgs)', validate parameter 'listPackageArgs' 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.CommandLine.XPlat.ListPackageCommandRunner.ExecuteCommandAsync(NuGet.CommandLine.XPlat.ListPackageArgs)~System.Threading.Tasks.Task")]
[assembly: SuppressMessage("Build", "CA1822:Member GetLatestVersionPerSourceAsync does not access instance data and can be marked as static (Shared in VisualBasic)", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.ListPackageCommandRunner.GetLatestVersionPerSourceAsync(NuGet.Configuration.PackageSource,NuGet.CommandLine.XPlat.ListPackageArgs,System.String,System.Collections.Generic.IEnumerable{System.Lazy{NuGet.Protocol.Core.Types.INuGetResourceProvider}},System.Collections.Generic.Dictionary{System.String,System.Collections.Generic.IList{NuGet.Protocol.Core.Types.IPackageSearchMetadata}})~System.Threading.Tasks.Task")]
[assembly: SuppressMessage("Build", "CA1822:Member GetPackageMetadataFromSourceAsync does not access instance data and can be marked as static (Shared in VisualBasic)", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.ListPackageCommandRunner.GetPackageMetadataFromSourceAsync(NuGet.Configuration.PackageSource,NuGet.CommandLine.XPlat.ListPackageArgs,System.String,NuGet.Versioning.NuGetVersion,System.Collections.Generic.IEnumerable{System.Lazy{NuGet.Protocol.Core.Types.INuGetResourceProvider}},System.Collections.Generic.Dictionary{System.String,System.Collections.Generic.IList{NuGet.Protocol.Core.Types.IPackageSearchMetadata}})~System.Threading.Tasks.Task")]
[assembly: SuppressMessage("Build", "CA1822:Member GetUpdateLevel does not access instance data and can be marked as static (Shared in VisualBasic)", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.ListPackageCommandRunner.GetUpdateLevel(NuGet.Versioning.NuGetVersion,NuGet.Versioning.NuGetVersion)~NuGet.CommandLine.XPlat.UpdateLevel")]
[assembly: SuppressMessage("Build", "CA1822:Member MeetsConstraints does not access instance data and can be marked as static (Shared in VisualBasic)", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.ListPackageCommandRunner.MeetsConstraints(NuGet.Versioning.NuGetVersion,NuGet.CommandLine.XPlat.InstalledPackageReference,NuGet.CommandLine.XPlat.ListPackageArgs)~System.Boolean")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void MSBuildAPIUtility.AddPackageReferencePerTFM(string projectPath, LibraryDependency libraryDependency, IEnumerable<string> frameworks)', validate parameter 'libraryDependency' 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.CommandLine.XPlat.MSBuildAPIUtility.AddPackageReferencePerTFM(System.String,NuGet.LibraryModel.LibraryDependency,System.Collections.Generic.IEnumerable{System.String})")]
Expand All @@ -32,9 +30,5 @@
[assembly: SuppressMessage("Build", "CA1303:Method 'int Program.MainInternal(string[] args, CommandOutputLogger log)' passes a literal string as parameter 'value' of a call to 'void Console.WriteLine(string value)'. Retrieve the following string(s) from a resource table instead: \"Waiting for debugger to attach.\".", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.Program.MainInternal(System.String[],NuGet.CommandLine.XPlat.CommandOutputLogger)~System.Int32")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void RemovePackageReferenceCommand.Register(CommandLineApplication app, Func<ILogger> getLogger, Func<IPackageReferenceCommandRunner> getCommandRunner)', validate parameter 'app' 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.CommandLine.XPlat.RemovePackageReferenceCommand.Register(Microsoft.Extensions.CommandLineUtils.CommandLineApplication,System.Func{NuGet.Common.ILogger},System.Func{NuGet.CommandLine.XPlat.IPackageReferenceCommandRunner})")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'Task<int> RemovePackageReferenceCommandRunner.ExecuteCommand(PackageReferenceArgs packageReferenceArgs, MSBuildAPIUtility msBuild)', validate parameter 'msBuild' 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.CommandLine.XPlat.RemovePackageReferenceCommandRunner.ExecuteCommand(NuGet.CommandLine.XPlat.PackageReferenceArgs,NuGet.CommandLine.XPlat.MSBuildAPIUtility)~System.Threading.Tasks.Task{System.Int32}")]
[assembly: SuppressMessage("Build", "CA1305:The behavior of 'string.Format(string, object)' could vary based on the current user's locale settings. Replace this call in 'ProjectPackagesPrintUtility.PrintPackagesAsync(IEnumerable<FrameworkPackages>, string, bool, bool, bool)' with a call to 'string.Format(IFormatProvider, string, params object[])'.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.Utility.ProjectPackagesPrintUtility.PrintPackagesAsync(System.Collections.Generic.IEnumerable{NuGet.CommandLine.XPlat.FrameworkPackages},System.String,System.Boolean,System.Boolean,System.Boolean)~System.Threading.Tasks.Task{NuGet.CommandLine.XPlat.Utility.PrintPackagesResult}")]
[assembly: SuppressMessage("Build", "CA1814:arrValues is a multidimensional array. Replace it with a jagged array if possible.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.Utility.TableParser.GetMaxColumnsWidth(System.String[,])~System.Int32[]")]
[assembly: SuppressMessage("Build", "CA1814:arrValues is a multidimensional array. Replace it with a jagged array if possible.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.Utility.TableParser.ToStringTable``1(``0[],System.String[,])~System.Collections.Generic.IEnumerable{System.String}")]
[assembly: SuppressMessage("Build", "CA1814:ToStringTableAsync uses a multidimensional array of string[*,*]. Replace it with a jagged array if possible.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.CommandLine.XPlat.Utility.TableParser.ToStringTableAsync``1(``0[],System.String[],System.Func{``0,System.Threading.Tasks.Task{System.Object}}[])~System.Threading.Tasks.Task{System.Collections.Generic.IEnumerable{System.String}}")]
[assembly: SuppressMessage("Build", "CA1819:Properties should not return arrays", Justification = "<Pending>", Scope = "member", Target = "~P:NuGet.CommandLine.XPlat.PackageReferenceArgs.Frameworks")]
[assembly: SuppressMessage("Build", "CA1819:Properties should not return arrays", Justification = "<Pending>", Scope = "member", Target = "~P:NuGet.CommandLine.XPlat.PackageReferenceArgs.Sources")]
1 change: 0 additions & 1 deletion src/NuGet.Core/NuGet.Commands/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
[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}")]
[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}")]
[assembly: SuppressMessage("Build", "CA1305:The behavior of 'string.Format(string, object)' could vary based on the current user's locale settings. Replace this call in 'SignCommandRunner.GetCertificateAsync(SignArgs)' with a call to 'string.Format(IFormatProvider, string, params object[])'.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.SignCommandRunner.GetCertificateAsync(NuGet.Commands.SignArgs)~System.Threading.Tasks.Task{System.Security.Cryptography.X509Certificates.X509Certificate2}")]
[assembly: SuppressMessage("Build", "CA1822:Member GetDependencies does not access instance data and can be marked as static (Shared in VisualBasic)", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.SourceRepositoryDependencyProvider.GetDependencies(NuGet.Protocol.Core.Types.FindPackageByIdDependencyInfo,NuGet.Frameworks.NuGetFramework)~System.Collections.Generic.IEnumerable{NuGet.LibraryModel.LibraryDependency}")]
[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})")]
[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")]
[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}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public SourceRepositoryDependencyProvider(
/// <exception cref="ArgumentNullException">Thrown if <paramref name="sourceRepository" />
/// is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="logger" /> is <c>null</c>.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="cacheContext" /> is <c>null</c>.</exception>
public SourceRepositoryDependencyProvider(
SourceRepository sourceRepository,
ILogger logger,
Expand All @@ -95,24 +94,9 @@ public SourceRepositoryDependencyProvider(
LocalPackageFileCache fileCache,
bool isFallbackFolderSource)
{
if (sourceRepository == null)
{
throw new ArgumentNullException(nameof(sourceRepository));
}

if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}

if (cacheContext == null)
{
throw new ArgumentNullException(nameof(cacheContext));
}

_sourceRepository = sourceRepository;
_logger = logger;
_cacheContext = cacheContext;
_sourceRepository = sourceRepository ?? throw new ArgumentNullException(nameof(sourceRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_cacheContext = cacheContext ?? throw new ArgumentNullException(nameof(cacheContext));
_ignoreFailedSources = ignoreFailedSources;
_ignoreWarning = ignoreWarning;
_packageFileCache = fileCache;
Expand Down Expand Up @@ -362,9 +346,9 @@ private async Task<LibraryDependencyInfo> GetDependenciesCoreAsync(
packageInfo.PackageIdentity.Version,
match.Type);

var dependencies = GetDependencies(packageInfo, targetFramework);
IEnumerable<LibraryDependency> dependencyGroup = GetDependencies(packageInfo, targetFramework);

return LibraryDependencyInfo.Create(originalIdentity, targetFramework, dependencies);
return LibraryDependencyInfo.Create(originalIdentity, targetFramework, dependencies: dependencyGroup);
}
}

Expand Down Expand Up @@ -452,7 +436,7 @@ public async Task<IPackageDownloader> GetPackageDownloaderAsync(
return null;
}

private IEnumerable<LibraryDependency> GetDependencies(
private static IEnumerable<LibraryDependency> GetDependencies(
FindPackageByIdDependencyInfo packageInfo,
NuGetFramework targetFramework)
{
Expand All @@ -470,6 +454,15 @@ private IEnumerable<LibraryDependency> GetDependencies(
dependencyGroup = NuGetFrameworkUtility.GetNearest(packageInfo.DependencyGroups, dualCompatibilityFramework.SecondaryFramework, item => item.TargetFramework);
}

// FrameworkReducer.GetNearest does not consider ATF since it is used for more than just compat
if (dependencyGroup == null &&
targetFramework is AssetTargetFallbackFramework assetTargetFallbackFramework)
{
dependencyGroup = NuGetFrameworkUtility.GetNearest(packageInfo.DependencyGroups,
assetTargetFallbackFramework.AsFallbackFramework(),
item => item.TargetFramework);
}

if (dependencyGroup != null)
{
return dependencyGroup.Packages.Select(PackagingUtility.GetLibraryDependencyFromNuspec).ToArray();
Expand Down
Loading