-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Repeatable build using Project lock file implementation
generating/ updating project lock file consuming project lock file during restore in VS Validation of package's sha512 and added error messages as appropriate Test infra for legacy PackageReference func tests Base workflow is completed
- Loading branch information
1 parent
16fdc22
commit 0b0e8bd
Showing
49 changed files
with
2,963 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using NuGet.Common; | ||
using NuGet.Frameworks; | ||
using NuGet.LibraryModel; | ||
using NuGet.Packaging.Core; | ||
using NuGet.ProjectModel; | ||
using NuGet.Shared; | ||
|
||
namespace NuGet.Commands | ||
{ | ||
public class NuGetLockFileBuilder | ||
{ | ||
private readonly int _lockFileVersion; | ||
public NuGetLockFileBuilder(int lockFileVersion) | ||
{ | ||
_lockFileVersion = lockFileVersion; | ||
} | ||
|
||
public NuGetLockFile CreateNuGetLockFile(LockFile assetsFile) | ||
{ | ||
var lockFile = new NuGetLockFile() | ||
{ | ||
Version = _lockFileVersion | ||
}; | ||
|
||
var libraryLookup = assetsFile.Libraries.Where(e => e.Type == LibraryType.Package) | ||
.ToDictionary(e => new PackageIdentity(e.Name, e.Version)); | ||
|
||
foreach (var target in assetsFile.Targets) | ||
{ | ||
var nuGettarget = new NuGetLockFileTarget() | ||
{ | ||
TargetFramework = target.TargetFramework, | ||
RuntimeIdentifier = target.RuntimeIdentifier | ||
}; | ||
|
||
var framework = assetsFile.PackageSpec.TargetFrameworks.FirstOrDefault( | ||
f => EqualityUtility.EqualsWithNullCheck(f.FrameworkName, target.TargetFramework)); | ||
|
||
var lilbraries = 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)); | ||
|
||
lilbraries = target.Libraries.Where(lib => !onlyTFM.Libraries.Any(tfmLib => tfmLib.Equals(lib))).ToList(); | ||
} | ||
|
||
foreach (var library in lilbraries.Where(e => e.Type == LibraryType.Package)) | ||
{ | ||
var identity = new PackageIdentity(library.Name, library.Version); | ||
|
||
var dependency = new LockFileDependency() | ||
{ | ||
Id = library.Name, | ||
ResolvedVersion = library.Version, | ||
Sha512 = libraryLookup[identity].Sha512, | ||
Dependencies = library.Dependencies | ||
}; | ||
|
||
var framework_dep = framework.Dependencies.FirstOrDefault( | ||
dep => PathUtility.GetStringComparerBasedOnOS().Equals(dep.Name, library.Name)); | ||
|
||
if (framework_dep != null) | ||
{ | ||
dependency.Type = PackageInstallationType.Direct; | ||
dependency.RequestedVersion = framework_dep.LibraryRange.VersionRange; | ||
} | ||
else | ||
{ | ||
dependency.Type = PackageInstallationType.Transitive; | ||
} | ||
|
||
nuGettarget.Dependencies.Add(dependency); | ||
} | ||
|
||
foreach (var projectRef in lilbraries.Where(e => e.Type == LibraryType.Project || e.Type == LibraryType.ExternalProject)) | ||
{ | ||
var dependency = new LockFileDependency() | ||
{ | ||
Id = projectRef.Name, | ||
Dependencies = projectRef.Dependencies, | ||
Type = PackageInstallationType.Project | ||
}; | ||
|
||
nuGettarget.Dependencies.Add(dependency); | ||
} | ||
|
||
nuGettarget.Dependencies = nuGettarget.Dependencies.OrderBy(d => d.Type).ToList(); | ||
|
||
lockFile.Targets.Add(nuGettarget); | ||
} | ||
|
||
return lockFile; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.