示例#1
0
        public void LockFile_IsValidForPackageSpec_DifferentToolVersions()
        {
            // Arrange
            var lockFile = new LockFile
            {
                ProjectFileDependencyGroups =
                {
                    new ProjectFileDependencyGroup("", new string[0])
                },
                ProjectFileToolGroups =
                {
                    new ProjectFileDependencyGroup(LockFile.ToolFramework.ToString(), new [] { "DependencyA >= 2.0.0" })
                }
            };

            var packageSpec = new PackageSpec(new JObject())
            {
                Dependencies = new List <LibraryDependency>(),
                Tools        = new List <ToolDependency>
                {
                    new ToolDependency
                    {
                        LibraryRange = new LibraryRange
                        {
                            Name           = "DependencyA",
                            TypeConstraint = LibraryDependencyTarget.Package,
                            VersionRange   = VersionRange.Parse("1.0.0")
                        }
                    }
                }
            };

            // Act & Assert
            Assert.False(lockFile.IsValidForPackageSpec(packageSpec));
        }
        private bool ShouldRelockFile(LockFile existingLockFile, PackageSpec project)
        {
            bool relockFile = false;

            if (existingLockFile != null &&
                existingLockFile.IsLocked &&
                !existingLockFile.IsValidForPackageSpec(project, _request.LockFileVersion))
            {
                // The lock file was locked, but the project.json is out of date
                relockFile = true;
                existingLockFile.IsLocked = false;
                _logger.LogMinimal(Strings.Log_LockFileOutOfDate);
            }
            return(relockFile);
        }
示例#3
0
        private int SummarizeLockfile(PackageSpec project, LockFile lockfile, string targetName)
        {
            _log.LogInformation($"Locked: {lockfile.IsLocked}");

            if (project == null)
            {
                _log.LogInformation($"Up-to-date: Unknown");
            }
            else
            {
                _log.LogInformation($"Up-to-date: {lockfile.IsValidForPackageSpec(project)}");
            }

            _log.LogInformation("Project Dependencies:");
            foreach (var group in lockfile.ProjectFileDependencyGroups)
            {
                var fxName = string.IsNullOrEmpty(group.FrameworkName) ? "All Frameworks" : group.FrameworkName;
                if (group.Dependencies.Any())
                {
                    _log.LogInformation($" {fxName}");
                    foreach (var dep in group.Dependencies)
                    {
                        _log.LogInformation($"  * {dep}");
                    }
                }
                else
                {
                    _log.LogInformation($" {fxName}: none");
                }
            }

            _log.LogInformation("All Libraries:");
            foreach (var lib in lockfile.Libraries)
            {
                _log.LogInformation($"* {lib.Name} {lib.Version}");
            }

            IEnumerable <LockFileTarget> targets = lockfile.Targets;

            if (!string.IsNullOrEmpty(targetName))
            {
                var parts = targetName.Split('/');
                var tfm   = NuGetFramework.Parse(parts[0]);
                var rid   = parts[1];
                targets = targets.Where(t => string.Equals(rid, t.RuntimeIdentifier, StringComparison.Ordinal) && tfm.Equals(t.TargetFramework));
            }

            foreach (var target in targets)
            {
                _log.LogInformation($"Target: {target.TargetFramework} {target.RuntimeIdentifier}");
                foreach (var lib in target.Libraries)
                {
                    string provides = string.Empty;
                    if (lib.NativeLibraries.Any())
                    {
                        provides += Native + ",";
                    }
                    if (lib.RuntimeAssemblies.Any())
                    {
                        provides += Runtime + ",";
                    }
                    if (lib.CompileTimeAssemblies.Any())
                    {
                        provides += Compile + ",";
                    }
                    if (lib.FrameworkAssemblies.Any())
                    {
                        provides += Framework + ",";
                    }
                    provides = provides.TrimEnd(',');
                    if (string.IsNullOrEmpty(provides))
                    {
                        provides = Nothing;
                    }
                    _log.LogInformation($" * [{provides}] {lib.Name} {lib.Version}");
                }
            }
            return(0);
        }