public static IEnumerable <LockFileTargetLibrary> GetRuntimeLibraries(this LockFileTarget lockFileTarget)
        {
            IEnumerable <LockFileTargetLibrary>        runtimeLibraries = lockFileTarget.Libraries;
            Dictionary <string, LockFileTargetLibrary> libraryLookup    =
                runtimeLibraries.ToDictionary(e => e.Name, StringComparer.OrdinalIgnoreCase);

            HashSet <string> allExclusionList = new HashSet <string>();

            if (lockFileTarget.IsPortable())
            {
                allExclusionList.UnionWith(lockFileTarget.GetPlatformExclusionList(libraryLookup));
            }

            return(runtimeLibraries.Filter(allExclusionList).ToArray());
        }
Exemple #2
0
        public DependencyContext Build(
            SingleProjectInfo mainProjectInfo,
            CompilationOptions compilationOptions,
            LockFile lockFile,
            NuGetFramework framework,
            string runtime)
        {
            bool includeCompilationLibraries = compilationOptions != null;

            LockFileTarget lockFileTarget = lockFile.GetTarget(framework, runtime);

            IEnumerable <LockFileTargetLibrary> runtimeExports     = lockFileTarget.GetRuntimeLibraries();
            IEnumerable <LockFileTargetLibrary> compilationExports =
                includeCompilationLibraries ?
                lockFileTarget.GetCompileLibraries() :
                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 = lockFile.Libraries.ToDictionary(l => l.Name, StringComparer.OrdinalIgnoreCase);

            var runtimeSignature = GenerateRuntimeSignature(runtimeExports);

            IEnumerable <RuntimeLibrary> runtimeLibraries =
                GetLibraries(runtimeExports, libraryLookup, dependencyLookup, runtime: true).Cast <RuntimeLibrary>();

            IEnumerable <CompilationLibrary> compilationLibraries;

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

            return(new DependencyContext(
                       new TargetInfo(framework.DotNetFrameworkName, runtime, runtimeSignature, lockFileTarget.IsPortable()),
                       compilationOptions ?? CompilationOptions.Default,
                       compilationLibraries,
                       runtimeLibraries,
                       new RuntimeFallbacks[] { }));
        }