Skip to content
Open
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
2 changes: 0 additions & 2 deletions src/NuGet.Core/NuGet.Commands/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
[assembly: SuppressMessage("Build", "CA2000:Call System.IDisposable.Dispose on object created by 'new LocalPackageArchiveDownloader(' before all references to it are out of scope.", Justification = "The following using statement disposes LocalPackageArchiveDownloader instance", Scope = "member", Target = "~M:NuGet.Commands.OriginalCaseGlobalPackageFolder.CopyPackagesToOriginalCaseAsync(System.Collections.Generic.IEnumerable{NuGet.Commands.RestoreTargetGraph},System.Threading.CancellationToken)~System.Threading.Tasks.Task")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'Task OriginalCaseGlobalPackageFolder.CopyPackagesToOriginalCaseAsync(IEnumerable<RestoreTargetGraph> graphs, CancellationToken token)', 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.OriginalCaseGlobalPackageFolder.CopyPackagesToOriginalCaseAsync(System.Collections.Generic.IEnumerable{NuGet.Commands.RestoreTargetGraph},System.Threading.CancellationToken)~System.Threading.Tasks.Task")]
[assembly: SuppressMessage("Build", "CA1308:In method 'CreateNuGetLockFile', replace the call to 'ToLowerInvariant' with 'ToUpperInvariant'.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.PackagesLockFileBuilder.CreateNuGetLockFile(NuGet.ProjectModel.LockFile)~NuGet.ProjectModel.PackagesLockFile")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'PackagesLockFile PackagesLockFileBuilder.CreateNuGetLockFile(LockFile assetsFile)', validate parameter 'assetsFile' 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.PackagesLockFileBuilder.CreateNuGetLockFile(NuGet.ProjectModel.LockFile)~NuGet.ProjectModel.PackagesLockFile")]
[assembly: SuppressMessage("Build", "CA1822:Member CreateNuGetLockFile does not access instance data and can be marked as static (Shared in VisualBasic)", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.PackagesLockFileBuilder.CreateNuGetLockFile(NuGet.ProjectModel.LockFile)~NuGet.ProjectModel.PackagesLockFile")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'string PackageSourceProviderExtensions.ResolveAndValidateSource(IPackageSourceProvider sourceProvider, string source)', validate parameter 'sourceProvider' 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.PackageSourceProviderExtensions.ResolveAndValidateSource(NuGet.Configuration.IPackageSourceProvider,System.String)~System.String")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'PackageSpecificWarningProperties PackageSpecificWarningProperties.CreatePackageSpecificWarningProperties(PackageSpec packageSpec)', validate parameter 'packageSpec' 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.PackageSpecificWarningProperties.CreatePackageSpecificWarningProperties(NuGet.ProjectModel.PackageSpec)~NuGet.Commands.PackageSpecificWarningProperties")]
Expand Down Expand Up @@ -177,7 +176,6 @@
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.VulnerabilityInformationProvider.GetVulnerabilityInfoAsync(System.Threading.CancellationToken)~System.Threading.Tasks.Task{NuGet.Protocol.Model.GetVulnerabilityInfoResult}")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.ListCommandRunner.PrintPackages(NuGet.Commands.ListArgs,NuGet.Common.IEnumeratorAsync{NuGet.Protocol.Core.Types.IPackageSearchMetadata})~System.Threading.Tasks.Task")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.LockFileBuilder.EnsureUniqueLockFileLibraries(NuGet.ProjectModel.LockFile)~System.Collections.Generic.Dictionary{System.ValueTuple{System.String,NuGet.Versioning.NuGetVersion},NuGet.ProjectModel.LockFileLibrary}")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.PackagesLockFileBuilder.GetPackagesLockFileVersion(NuGet.ProjectModel.LockFile)~System.Int32")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.RestoreCommand.ConcatAsString``1(System.Collections.Generic.IEnumerable{``0})~System.String")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.TrustedSignersCommandRunner.ValidateAndParseFingerprintAlgorithm(System.String)~NuGet.Common.HashAlgorithmName")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Commands.TrustedSignersCommandRunner.ValidateAndParseV3ServiceIndexUrl(System.String)~System.Uri")]
Expand Down
25 changes: 14 additions & 11 deletions src/NuGet.Core/NuGet.Commands/PackagesLockFileBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#nullable disable

using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -19,6 +17,7 @@ public class PackagesLockFileBuilder
{
public PackagesLockFile CreateNuGetLockFile(LockFile assetsFile)
{
if (assetsFile == null) throw new ArgumentNullException(nameof(assetsFile));
var lockFile = new PackagesLockFile(GetPackagesLockFileVersion(assetsFile));

var libraryLookup = assetsFile.Libraries.Where(e => e.Type == LibraryType.Package)
Expand All @@ -29,18 +28,17 @@ public PackagesLockFile CreateNuGetLockFile(LockFile assetsFile)
var nuGettarget = new PackagesLockFileTarget()
{
TargetFramework = target.TargetFramework,
RuntimeIdentifier = target.RuntimeIdentifier
RuntimeIdentifier = target.RuntimeIdentifier,
TargetAlias = lockFile.Version >= 3 ? target.TargetAlias : null
};

var framework = assetsFile.PackageSpec.TargetFrameworks.FirstOrDefault(
f => EqualityUtility.EqualsWithNullCheck(f.FrameworkName, target.TargetFramework));

TargetFrameworkInformation? framework = assetsFile.PackageSpec.GetTargetFramework(target.TargetAlias);
IEnumerable<LockFileTargetLibrary> libraries = target.Libraries;

// check if this is RID-based graph then only add those libraries which differ from original TFM.
if (!string.IsNullOrEmpty(target.RuntimeIdentifier))
{
var onlyTFM = assetsFile.Targets.First(t => EqualityUtility.EqualsWithNullCheck(t.TargetFramework, target.TargetFramework));
LockFileTarget onlyTFM = assetsFile.Targets.First(t => EqualityUtility.EqualsWithNullCheck(t.TargetAlias, target.TargetAlias));

libraries = target.Libraries.Where(lib => !onlyTFM.Libraries.Any(tfmLib => tfmLib.Equals(lib)));
}
Expand All @@ -60,7 +58,7 @@ public PackagesLockFile CreateNuGetLockFile(LockFile assetsFile)
var framework_dep = framework?.Dependencies.FirstOrDefault(
dep => StringComparer.OrdinalIgnoreCase.Equals(dep.Name, library.Name));

CentralPackageVersion centralPackageVersion = null;
CentralPackageVersion? centralPackageVersion = null;
framework?.CentralPackageVersions.TryGetValue(library.Name, out centralPackageVersion);

if (framework_dep != null)
Expand Down Expand Up @@ -118,15 +116,20 @@ public PackagesLockFile CreateNuGetLockFile(LockFile assetsFile)
return lockFile;
}

private int GetPackagesLockFileVersion(LockFile assetsFile)
private static int GetPackagesLockFileVersion(LockFile assetsFile)
{
if (RestoreCommand.HasDuplicateFrameworks(assetsFile.PackageSpec))
{
return 3; // Version 3 for alias support
}

// Increase the version only for the projects opted-in central version management
if (assetsFile.PackageSpec.RestoreMetadata.CentralPackageVersionsEnabled)
{
return PackagesLockFileFormat.PackagesLockFileVersion;
return 2;
}

return PackagesLockFileFormat.Version;
return 1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ NuGet.Commands.PackageSpecificWarningProperties
NuGet.Commands.PackageSpecificWarningProperties.PackageSpecificWarningProperties() -> void
~NuGet.Commands.PackageSpecificWarningProperties.Properties.get -> System.Collections.Generic.IDictionary<NuGet.Common.NuGetLogCode, System.Collections.Generic.IDictionary<string, System.Collections.Generic.ISet<NuGet.Frameworks.NuGetFramework>>>
NuGet.Commands.PackagesLockFileBuilder
~NuGet.Commands.PackagesLockFileBuilder.CreateNuGetLockFile(NuGet.ProjectModel.LockFile assetsFile) -> NuGet.ProjectModel.PackagesLockFile
NuGet.Commands.PackagesLockFileBuilder.CreateNuGetLockFile(NuGet.ProjectModel.LockFile! assetsFile) -> NuGet.ProjectModel.PackagesLockFile!
NuGet.Commands.PackagesLockFileBuilder.PackagesLockFileBuilder() -> void
NuGet.Commands.PushRunner
NuGet.Commands.RemoveClientCertArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ NuGet.Commands.PackageSpecificWarningProperties
NuGet.Commands.PackageSpecificWarningProperties.PackageSpecificWarningProperties() -> void
~NuGet.Commands.PackageSpecificWarningProperties.Properties.get -> System.Collections.Generic.IDictionary<NuGet.Common.NuGetLogCode, System.Collections.Generic.IDictionary<string, System.Collections.Generic.ISet<NuGet.Frameworks.NuGetFramework>>>
NuGet.Commands.PackagesLockFileBuilder
~NuGet.Commands.PackagesLockFileBuilder.CreateNuGetLockFile(NuGet.ProjectModel.LockFile assetsFile) -> NuGet.ProjectModel.PackagesLockFile
NuGet.Commands.PackagesLockFileBuilder.CreateNuGetLockFile(NuGet.ProjectModel.LockFile! assetsFile) -> NuGet.ProjectModel.PackagesLockFile!
NuGet.Commands.PackagesLockFileBuilder.PackagesLockFileBuilder() -> void
NuGet.Commands.PushRunner
NuGet.Commands.RemoveClientCertArgs
Expand Down
Loading