public DependencyContextBuilder(SingleProjectInfo mainProjectInfo, bool includeRuntimeFileVersions, RuntimeGraph runtimeGraph, ProjectContext projectContext)
        {
            _mainProjectInfo            = mainProjectInfo;
            _includeRuntimeFileVersions = includeRuntimeFileVersions;
            _runtimeGraph = runtimeGraph;

            var libraryLookup = new LockFileLookup(projectContext.LockFile);

            _dependencyLibraries = projectContext.LockFileTarget.Libraries
                                   .Select(lockFileTargetLibrary =>
            {
                var dependencyLibrary = new DependencyLibrary(lockFileTargetLibrary.Name, lockFileTargetLibrary.Version, lockFileTargetLibrary.Type);

                LockFileLibrary library;
                if (libraryLookup.TryGetLibrary(lockFileTargetLibrary, out library))
                {
                    dependencyLibrary.Sha512         = library.Sha512;
                    dependencyLibrary.Path           = library.Path;
                    dependencyLibrary.MSBuildProject = library.MSBuildProject;
                }

                return(dependencyLibrary);
            }).ToDictionary(d => d.Name, StringComparer.OrdinalIgnoreCase);

            _libraryDependencies = new Dictionary <string, List <LibraryDependency> >(StringComparer.OrdinalIgnoreCase);
            foreach (var library in projectContext.LockFileTarget.Libraries)
            {
                _libraryDependencies[library.Name] = library.Dependencies
                                                     .Select(d => new LibraryDependency()
                {
                    Name       = d.Id,
                    MinVersion = d.VersionRange.MinVersion
                }).ToList();
            }

            _mainProjectDependencies = projectContext.GetTopLevelDependencies().ToList();
            _packagesToBeFiltered    = projectContext.PackagesToBeFiltered;

            _isFrameworkDependent = projectContext.IsFrameworkDependent;
            _platformLibrary      = projectContext.PlatformLibrary?.Name;
            _dotnetFrameworkName  = projectContext.LockFileTarget.TargetFramework.DotNetFrameworkName;
            _runtimeIdentifier    = projectContext.LockFileTarget.RuntimeIdentifier;
            _isPortable           = projectContext.IsPortable;

            _usedLibraryNames = new HashSet <string>(_dependencyLibraries.Keys, StringComparer.OrdinalIgnoreCase);
        }
Example #2
0
        private List <Dependency> GetProjectDependencies(
            ProjectContext projectContext,
            Dictionary <string, Dependency> dependencyLookup)
        {
            List <Dependency> dependencies = new List <Dependency>();

            foreach (string dependencyName in projectContext.GetTopLevelDependencies())
            {
                Dependency dependency;
                if (dependencyLookup.TryGetValue(dependencyName, out dependency))
                {
                    dependencies.Add(dependency);
                }
            }

            return(dependencies);
        }