예제 #1
0
 private void WriteLockFile(string dir, string libName, string version)
 {
     var lockFile = new LockFile
     {
         Islocked = false,
         Libraries = new List<LockFileLibrary>
                     {
                         new LockFileLibrary
                         {
                             Name = libName,
                             Version = new NuGet.SemanticVersion(version),
                             Sha512 = "TestSha"
                         }
                     }
     };
     var lockFormat = new LockFileFormat();
     lockFormat.Write($"{dir}/project.lock.json", lockFile);
 }
예제 #2
0
 public void ApplyLockFile(LockFile lockFile)
 {
     _repository.ApplyLockFile(lockFile);
 }
예제 #3
0
        private void UpdateLockFile(PublishRoot root)
        {
            var lockFileFormat = new LockFileFormat();
            string lockFilePath;
            if (root.NoSource)
            {
                lockFilePath = Path.Combine(TargetPath, "root", LockFileFormat.LockFileName);
            }
            else
            {
                lockFilePath = Path.Combine(TargetPath, LockFileFormat.LockFileName);
            }

            LockFile lockFile;
            if (File.Exists(lockFilePath))
            {
                lockFile = lockFileFormat.Read(lockFilePath);
            }
            else
            {
                lockFile = new LockFile
                {
                    Islocked = false
                };

                var project = GetCurrentProject();

                // Restore dependency groups for future lockfile validation
                lockFile.ProjectFileDependencyGroups.Add(new ProjectFileDependencyGroup(
                    string.Empty,
                    project.Dependencies.Select(x => x.LibraryRange.ToString())));
                foreach (var frameworkInfo in project.GetTargetFrameworks())
                {
                    lockFile.ProjectFileDependencyGroups.Add(new ProjectFileDependencyGroup(
                        frameworkInfo.FrameworkName.ToString(),
                        frameworkInfo.Dependencies.Select(x => x.LibraryRange.ToString())));
                }
            }

            if (root.NoSource)
            {
                // The dependency group shared by all frameworks should only contain the main nupkg (i.e. entrypoint)
                lockFile.ProjectFileDependencyGroups.RemoveAll(g => string.IsNullOrEmpty(g.FrameworkName));
                lockFile.ProjectFileDependencyGroups.Add(new ProjectFileDependencyGroup(
                    string.Empty,
                    new[] { _libraryDescription.LibraryRange.ToString() }));
            }

            var repository = new PackageRepository(root.TargetPackagesPath);
            var resolver = new DefaultPackagePathResolver(root.TargetPackagesPath);

            // For dependency projects that were published to nupkgs
            // Add them to lockfile to ensure the contents of lockfile are still valid
            using (var sha512 = SHA512.Create())
            {
                foreach (var publishProject in root.Projects.Where(p => p.IsPackage))
                {
                    var packageInfo = repository.FindPackagesById(publishProject.Name)
                        .SingleOrDefault();
                    if (packageInfo == null)
                    {
                        root.Reports.Information.WriteLine("Unable to locate published package {0} in {1}",
                            publishProject.Name.Yellow(),
                            repository.RepositoryRoot);
                        continue;
                    }

                    var package = packageInfo.Package;
                    var nupkgPath = resolver.GetPackageFilePath(package.Id, package.Version);

                    var project = publishProject.GetCurrentProject();
                    lockFile.Libraries.Add(LockFileUtils.CreateLockFileLibraryForProject(
                        project,
                        package,
                        sha512,
                        project.GetTargetFrameworks().Select(f => f.FrameworkName),
                        resolver));
                }
            }

            lockFileFormat.Write(lockFilePath, lockFile);
        }
예제 #4
0
        public void LibrariesAreResolvedCorrectly(string packageName, string framework, bool resolved)
        {
            var repo = new PackageRepository("path/to/packages");
            var resolver = new NuGetDependencyResolver(repo);

            var net45Target = new LockFileTarget
            {
                TargetFramework = new FrameworkName(".NETFramework,Version=v4.5"),
                Libraries = new List<LockFileTargetLibrary>
                {
                    new LockFileTargetLibrary
                    {
                        Name = "MetaPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "Net451LibPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "Net451RefPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "AssemblyPlaceholderPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                        CompileTimeAssemblies = new List<LockFileItem> { Path.Combine("ref", "net45", "_._") },
                        RuntimeAssemblies = new List<LockFileItem> { Path.Combine("lib", "net45", "_._") }
                    }
                }
            };

            var dnx451Target = new LockFileTarget
            {
                TargetFramework = new FrameworkName("DNX,Version=v4.5.1"),
                Libraries = new List<LockFileTargetLibrary>
                {
                    new LockFileTargetLibrary
                    {
                        Name = "MetaPackage",
                        Version = SemanticVersion.Parse("1.0.0")
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "Net451LibPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                        CompileTimeAssemblies = new List<LockFileItem> { Path.Combine("lib", "net451", "Net451LibPackage.dll") },
                        RuntimeAssemblies = new List<LockFileItem> { Path.Combine("lib", "net451", "Net451LibPackage.dll") }
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "Net451RefPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                        CompileTimeAssemblies = new List<LockFileItem> { Path.Combine("ref", "net451", "Net451LibPackage.dll") }
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "AssemblyPlaceholderPackage",
                        Version = SemanticVersion.Parse("1.0.0")
                    }
                }
            };

            var metaPackageLibrary = new LockFileLibrary
            {
                Name = "MetaPackage",
                Version = SemanticVersion.Parse("1.0.0")
            };

            var net451LibPackageLibrary = new LockFileLibrary
            {
                Name = "Net451LibPackage",
                Version = SemanticVersion.Parse("1.0.0"),
                Files = new List<string>
                {
                    Path.Combine("lib", "net451", "Net451LibPackage.dll"),
                    Path.Combine("lib", "net451", "Net451LibPackage.xml")
                }
            };

            var net451RefPackageLibrary = new LockFileLibrary
            {
                Name = "Net451RefPackage",
                Version = SemanticVersion.Parse("1.0.0"),
                Files = new List<string>
                {
                    Path.Combine("ref", "net451", "Net451LibPackage.dll")
                }
            };

            var assemblyPlaceholderPackageLibrary = new LockFileLibrary
            {
                Name = "AssemblyPlaceholderPackage",
                Version = SemanticVersion.Parse("1.0.0"),
                Files = new List<string>
                {
                    Path.Combine("lib", "net45", "_._"),
                    Path.Combine("ref", "net45", "_._"),
                }
            };

            var lockFile = new LockFile()
            {
                Targets = new List<LockFileTarget> { net45Target, dnx451Target },
                Libraries = new List<LockFileLibrary>
                {
                    metaPackageLibrary,
                    net451LibPackageLibrary,
                    net451RefPackageLibrary,
                    assemblyPlaceholderPackageLibrary
                }
            };

            resolver.ApplyLockFile(lockFile);

            var libToLookup = new LibraryRange(packageName, frameworkReference: false);
            Assert.Equal(resolved, resolver.GetDescription(libToLookup, new FrameworkName(framework)).Resolved);
        }
예제 #5
0
 public void ApplyLockFile(LockFile lockFile)
 {
     var stringComparer = _checkPackageIdCase ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;
     _lockFileLibraries = lockFile.Libraries.ToLookup(l => l.Name, stringComparer);
 }