예제 #1
0
        public DependencyContext Build()
        {
            bool includeCompilationLibraries = _compilationOptions != null;

            IEnumerable <LockFileTargetLibrary> runtimeExports     = _projectContext.GetRuntimeLibraries(_privateAssetPackageIds);
            IEnumerable <LockFileTargetLibrary> compilationExports =
                includeCompilationLibraries ?
                _projectContext.GetCompileLibraries(_privateAssetPackageIds) :
                Enumerable.Empty <LockFileTargetLibrary>();

            var dependencyLookup = compilationExports
                                   .Concat(runtimeExports)
                                   .Distinct()
                                   .Select(library => new Dependency(library.Name, library.Version.ToString()))
                                   .ToDictionary(dependency => dependency.Name, StringComparer.OrdinalIgnoreCase);

            var libraryLookup = new LockFileLookup(_projectContext.LockFile);

            var runtimeSignature = GenerateRuntimeSignature(runtimeExports);

            RuntimeLibrary projectRuntimeLibrary = GetProjectRuntimeLibrary(
                _mainProjectInfo,
                _projectContext,
                dependencyLookup);
            IEnumerable <RuntimeLibrary> runtimeLibraries =
                new[] { projectRuntimeLibrary }
            .Concat(GetLibraries(runtimeExports, libraryLookup, dependencyLookup, runtime: true).Cast <RuntimeLibrary>());

            IEnumerable <CompilationLibrary> compilationLibraries;

            if (includeCompilationLibraries)
            {
                CompilationLibrary projectCompilationLibrary = GetProjectCompilationLibrary(
                    _mainProjectInfo,
                    _projectContext,
                    dependencyLookup);
                compilationLibraries =
                    new[] { projectCompilationLibrary }
                .Concat(GetFrameworkLibraries())
                .Concat(GetLibraries(compilationExports, libraryLookup, dependencyLookup, runtime: false).Cast <CompilationLibrary>());
            }
            else
            {
                compilationLibraries = Enumerable.Empty <CompilationLibrary>();
            }

            var targetInfo = new TargetInfo(
                _projectContext.LockFileTarget.TargetFramework.DotNetFrameworkName,
                _projectContext.LockFileTarget.RuntimeIdentifier,
                runtimeSignature,
                _projectContext.IsPortable);

            return(new DependencyContext(
                       targetInfo,
                       _compilationOptions ?? CompilationOptions.Default,
                       compilationLibraries,
                       runtimeLibraries,
                       new RuntimeFallbacks[] { }));
        }
예제 #2
0
 private IEnumerable <Library> GetLibraries(
     IEnumerable <LockFileTargetLibrary> exports,
     LockFileLookup libraryLookup,
     IDictionary <string, Dependency> dependencyLookup,
     bool runtime)
 {
     return(exports.Select(export => GetLibrary(export, libraryLookup, dependencyLookup, runtime)));
 }
예제 #3
0
        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);
        }
예제 #4
0
        private Library GetLibrary(
            LockFileTargetLibrary export,
            LockFileLookup libraryLookup,
            IDictionary <string, Dependency> dependencyLookup,
            bool runtime)
        {
            var  type      = export.Type;
            bool isPackage = type == "package";

            // TEMPORARY: All packages are serviceable in RC2
            // See https://github.com/dotnet/cli/issues/2569
            var serviceable         = isPackage;
            var libraryDependencies = new HashSet <Dependency>();

            foreach (PackageDependency libraryDependency in export.Dependencies)
            {
                Dependency dependency;
                if (dependencyLookup.TryGetValue(libraryDependency.Id, out dependency))
                {
                    libraryDependencies.Add(dependency);
                }
            }

            string            hash     = string.Empty;
            string            path     = null;
            string            hashPath = null;
            LockFileLibrary   library;
            SingleProjectInfo referenceProjectInfo = null;

            if (libraryLookup.TryGetLibrary(export, out library))
            {
                if (isPackage)
                {
                    if (!string.IsNullOrEmpty(library.Sha512))
                    {
                        hash     = "sha512-" + library.Sha512;
                        hashPath = _versionFolderPathResolver.GetHashFileName(export.Name, export.Version);
                    }

                    path = library.Path;
                }
                else if (type == "project")
                {
                    referenceProjectInfo = GetProjectInfo(library);
                }
            }

            if (runtime)
            {
                return(CreateRuntimeLibrary(
                           type.ToLowerInvariant(),
                           export.Name,
                           export.Version.ToString(),
                           hash,
                           CreateRuntimeAssemblyGroups(export, referenceProjectInfo),
                           CreateNativeLibraryGroups(export),
                           CreateResourceAssemblyGroups(export, referenceProjectInfo),
                           libraryDependencies,
                           serviceable,
                           path,
                           hashPath));
            }
            else
            {
                IEnumerable <string> assemblies = GetCompileTimeAssemblies(export, referenceProjectInfo);

                return(new CompilationLibrary(
                           type.ToLowerInvariant(),
                           export.Name,
                           export.Version.ToString(),
                           hash,
                           assemblies,
                           libraryDependencies,
                           serviceable,
                           path,
                           hashPath));
            }
        }
예제 #5
0
        private Library GetLibrary(
            LockFileTargetLibrary export,
            LockFileLookup libraryLookup,
            IDictionary <string, Dependency> dependencyLookup,
            bool runtime)
        {
            var  type      = export.Type;
            bool isPackage = export.IsPackage();

            // TEMPORARY: All packages are serviceable in RC2
            // See https://github.com/dotnet/cli/issues/2569
            var serviceable         = isPackage;
            var libraryDependencies = new HashSet <Dependency>();

            foreach (PackageDependency libraryDependency in export.Dependencies)
            {
                Dependency dependency;
                if (dependencyLookup.TryGetValue(libraryDependency.Id, out dependency))
                {
                    libraryDependencies.Add(dependency);
                }
            }

            string            hash     = string.Empty;
            string            path     = null;
            string            hashPath = null;
            LockFileLibrary   library;
            SingleProjectInfo referenceProjectInfo = null;

            if (libraryLookup.TryGetLibrary(export, out library))
            {
                if (isPackage)
                {
                    if (!string.IsNullOrEmpty(library.Sha512))
                    {
                        hash     = "sha512-" + library.Sha512;
                        hashPath = _versionFolderPathResolver.GetHashFileName(export.Name, export.Version);
                    }

                    path = library.Path;
                }
                else if (export.IsProject())
                {
                    referenceProjectInfo = GetProjectInfo(library);

                    if (referenceProjectInfo is UnreferencedProjectInfo)
                    {
                        // unreferenced ProjectInfos will be added later as simple dll dependencies
                        return(null);
                    }

                    if (runtime)
                    {
                        // DependencyReferences do not get passed to the compilation, so we should only
                        // process them when getting the runtime libraries.

                        foreach (var dependencyReference in referenceProjectInfo.DependencyReferences)
                        {
                            libraryDependencies.Add(
                                new Dependency(
                                    GetReferenceLibraryName(dependencyReference),
                                    dependencyReference.Version));
                        }
                    }
                }
            }

            if (runtime)
            {
                return(CreateRuntimeLibrary(
                           type.ToLowerInvariant(),
                           export.Name,
                           export.Version.ToString(),
                           hash,
                           CreateRuntimeAssemblyGroups(export, referenceProjectInfo),
                           CreateNativeLibraryGroups(export),
                           CreateResourceAssemblyGroups(export, referenceProjectInfo),
                           libraryDependencies,
                           serviceable,
                           path,
                           hashPath));
            }
            else
            {
                IEnumerable <string> assemblies = GetCompileTimeAssemblies(export, referenceProjectInfo);

                return(new CompilationLibrary(
                           type.ToLowerInvariant(),
                           export.Name,
                           export.Version.ToString(),
                           hash,
                           assemblies,
                           libraryDependencies,
                           serviceable,
                           path,
                           hashPath));
            }
        }
        private Library GetLibrary(
            LockFileTargetLibrary export,
            LockFileLookup libraryLookup,
            IDictionary <string, Dependency> dependencyLookup,
            bool runtime)
        {
            var  type      = export.Type;
            bool isPackage = export.IsPackage();

            // TEMPORARY: All packages are serviceable in RC2
            // See https://github.com/dotnet/cli/issues/2569
            var serviceable         = isPackage;
            var libraryDependencies = new HashSet <Dependency>();

            foreach (PackageDependency libraryDependency in export.Dependencies)
            {
                Dependency dependency;
                if (dependencyLookup.TryGetValue(libraryDependency.Id, out dependency))
                {
                    libraryDependencies.Add(dependency);
                }
            }

            string            hash     = string.Empty;
            string            path     = null;
            string            hashPath = null;
            LockFileLibrary   library;
            SingleProjectInfo referenceProjectInfo = null;

            if (libraryLookup.TryGetLibrary(export, out library))
            {
                if (isPackage)
                {
                    if (!string.IsNullOrEmpty(library.Sha512))
                    {
                        hash     = "sha512-" + library.Sha512;
                        hashPath = _versionFolderPathResolver.GetHashFileName(export.Name, export.Version);
                    }

                    path = library.Path;
                }
                else if (export.IsProject())
                {
                    referenceProjectInfo = GetProjectInfo(library);

                    if (referenceProjectInfo is UnreferencedProjectInfo)
                    {
                        // unreferenced ProjectInfos will be added later as simple dll dependencies
                        return(null);
                    }

                    if (runtime)
                    {
                        // DependencyReferences do not get passed to the compilation, so we should only
                        // process them when getting the runtime libraries.

                        foreach (var dependencyReference in referenceProjectInfo.DependencyReferences)
                        {
                            libraryDependencies.Add(
                                new Dependency(
                                    GetReferenceLibraryName(dependencyReference),
                                    dependencyReference.Version));
                        }
                    }
                }
            }

            if (runtime)
            {
                return(CreateRuntimeLibrary(
                           type.ToLowerInvariant(),
                           export.Name,
                           export.Version.ToString(),
                           hash,
                           CreateRuntimeAssemblyGroups(export, referenceProjectInfo),
                           CreateNativeLibraryGroups(export),
                           CreateResourceAssemblyGroups(export, referenceProjectInfo),
                           libraryDependencies,
                           serviceable,
                           path,
                           hashPath));
            }
            else
            {
                IEnumerable <string> assemblies = Enumerable.Empty <string>();

                //  In some situations, the assets file will include compilation assets under the RID-specific
                //  target, but not under the RID-less target.  The RID-less target is what is used for project
                //  compilation, so make sure we get those assets when writing the compile references to the assets
                //  file.
                //  This can happen when the runtime graph adds dependencies which don't have compile assets excluded.
                //  This was encountered with the 4.3.0 System.Security.Claims, System.Security.Principal.Windows, and
                //  System.Threading.Overlapped packages.
                LockFileTargetLibrary exportWithCompileAssets;
                if (_compilationTargetLibraries != null)
                {
                    _compilationTargetLibraries.TryGetValue(export.Name, out exportWithCompileAssets);
                }
                else
                {
                    exportWithCompileAssets = export;
                }
                if (exportWithCompileAssets != null)
                {
                    assemblies = GetCompileTimeAssemblies(exportWithCompileAssets, referenceProjectInfo);
                }

                return(new CompilationLibrary(
                           type.ToLowerInvariant(),
                           export.Name,
                           export.Version.ToString(),
                           hash,
                           assemblies,
                           libraryDependencies,
                           serviceable,
                           path,
                           hashPath));
            }
        }
        public DependencyContext Build()
        {
            bool includeCompilationLibraries = _compilationOptions != null;

            IEnumerable <LockFileTargetLibrary> runtimeExports     = _projectContext.GetRuntimeLibraries(_excludeFromPublishPackageIds);
            IEnumerable <LockFileTargetLibrary> compilationExports =
                includeCompilationLibraries ?
                _projectContext.GetCompileLibraries(_excludeFromPublishPackageIds) :
                Enumerable.Empty <LockFileTargetLibrary>();

            var dependencyLookup = compilationExports
                                   .Concat(runtimeExports)
                                   .Distinct()
                                   .Select(library => new Dependency(library.Name, library.Version.ToString()))
                                   .ToDictionary(dependency => dependency.Name, StringComparer.OrdinalIgnoreCase);

            var libraryLookup = new LockFileLookup(_projectContext.LockFile);

            var runtimeSignature = string.Empty;

            IEnumerable <RuntimeLibrary> runtimeLibraries = Enumerable.Empty <RuntimeLibrary>();

            if (_includeMainProjectInDepsFile)
            {
                runtimeLibraries = runtimeLibraries.Concat(new[]
                {
                    GetProjectRuntimeLibrary(
                        _mainProjectInfo,
                        _projectContext,
                        dependencyLookup,
                        includeCompilationLibraries)
                });
            }
            runtimeLibraries = runtimeLibraries
                               .Concat(GetRuntimePackLibraries(_runtimePackAssets))
                               .Concat(GetLibraries(runtimeExports, libraryLookup, dependencyLookup, runtime: true).Cast <RuntimeLibrary>())
                               .Concat(GetDirectReferenceRuntimeLibraries())
                               .Concat(GetDependencyReferenceRuntimeLibraries());

            IEnumerable <CompilationLibrary> compilationLibraries = Enumerable.Empty <CompilationLibrary>();

            if (includeCompilationLibraries)
            {
                if (_includeMainProjectInDepsFile)
                {
                    compilationLibraries = compilationLibraries.Concat(new[]
                    {
                        GetProjectCompilationLibrary(
                            _mainProjectInfo,
                            _projectContext,
                            dependencyLookup,
                            includeCompilationLibraries)
                    });
                }

                compilationLibraries = compilationLibraries
                                       .Concat(GetReferenceAssemblyLibraries())
                                       .Concat(GetLibraries(compilationExports, libraryLookup, dependencyLookup, runtime: false).Cast <CompilationLibrary>())
                                       .Concat(GetDirectReferenceCompilationLibraries());
            }

            var targetInfo = new TargetInfo(
                _projectContext.LockFileTarget.TargetFramework.DotNetFrameworkName,
                _projectContext.LockFileTarget.RuntimeIdentifier,
                runtimeSignature,
                _projectContext.IsPortable);

            return(new DependencyContext(
                       targetInfo,
                       _compilationOptions ?? CompilationOptions.Default,
                       compilationLibraries,
                       runtimeLibraries,
                       new RuntimeFallbacks[] { }));
        }