private bool IsValidForProject(Project project, out string message) { if (Version != Constants.LockFileVersion) { message = $"The expected lock file version does not match the actual version"; return(false); } message = $"Dependencies in {Project.ProjectFileName} were modified"; var actualTargetFrameworks = project.GetTargetFrameworks(); // The lock file should contain dependencies for each framework plus dependencies shared by all frameworks if (ProjectFileDependencyGroups.Count != actualTargetFrameworks.Count() + 1) { return(false); } foreach (var group in ProjectFileDependencyGroups) { IOrderedEnumerable <string> actualDependencies; var expectedDependencies = group.Dependencies.OrderBy(x => x); // If the framework name is empty, the associated dependencies are shared by all frameworks if (string.IsNullOrEmpty(group.FrameworkName)) { actualDependencies = project.Dependencies.Select(x => x.LibraryRange.ToString()).OrderBy(x => x); } else { var framework = actualTargetFrameworks .FirstOrDefault(f => string.Equals(f.FrameworkName.ToString(), group.FrameworkName, StringComparison.Ordinal)); if (framework == null) { return(false); } actualDependencies = framework.Dependencies.Select(d => d.LibraryRange.ToString()).OrderBy(x => x); } if (!actualDependencies.SequenceEqual(expectedDependencies)) { return(false); } } message = null; return(true); }
static IEnumerable<LibraryDescription> GetAllDeps(Project proj) => proj.GetTargetFrameworks().Select(f => f.FrameworkName) .SelectMany(f => { var context = new ApplicationHostContext { Project = proj, TargetFramework = f }; return ApplicationHostContext.GetRuntimeLibraries(context).Skip(1); // the first one is the self-reference }) .Distinct(LibraryUtils.Comparer) .OrderBy(l => l.Identity?.Name);
public bool IsValidForProject(Project project, out string message) { if (Version != Constants.LockFileVersion) { message = $"The expected lock file version does not match the actual version"; return false; } message = $"Dependencies in {Project.ProjectFileName} were modified"; var actualTargetFrameworks = project.GetTargetFrameworks(); // The lock file should contain dependencies for each framework plus dependencies shared by all frameworks if (ProjectFileDependencyGroups.Count != actualTargetFrameworks.Count() + 1) { return false; } foreach (var group in ProjectFileDependencyGroups) { IOrderedEnumerable<string> actualDependencies; var expectedDependencies = group.Dependencies.OrderBy(x => x); // If the framework name is empty, the associated dependencies are shared by all frameworks if (string.IsNullOrEmpty(group.FrameworkName)) { actualDependencies = project.Dependencies.Select(x => x.LibraryRange.ToString()).OrderBy(x => x); } else { var framework = actualTargetFrameworks .FirstOrDefault(f => string.Equals(f.FrameworkName.ToString(), group.FrameworkName, StringComparison.Ordinal)); if (framework == null) { return false; } actualDependencies = framework.Dependencies.Select(d => d.LibraryRange.ToString()).OrderBy(x => x); } if (!actualDependencies.SequenceEqual(expectedDependencies)) { return false; } } message = null; return true; }
static IEnumerable<LibraryDescription> GetAllDeps(Project proj) => proj.GetTargetFrameworks().Select(f => f.FrameworkName) .SelectMany(f => { var context = new ApplicationHostContext { Project = proj, TargetFramework = f }; IList<LibraryDescription> libs = null; while (libs == null) { try { libs = ApplicationHostContext.GetRuntimeLibraries(context); } catch (Exception e) { } } // the first library description is always self-reference, so skip it return libs.Skip(1); }) .Distinct(LibraryUtils.Comparer) .OrderBy(l => l.Identity?.Name);