示例#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[] { }));
        }
        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[] { }));
        }