public IEnumerable <ResolvedFile> Resolve(ProjectContext projectContext)
        {
            List <ResolvedFile> results = new List <ResolvedFile>();

            foreach (LockFileTargetLibrary targetLibrary in projectContext.GetRuntimeLibraries(_excludeFromPublishPackageIds))
            {
                if (targetLibrary.Type != "package")
                {
                    continue;
                }
                var targetLibraryPackage = new PackageIdentity(targetLibrary.Name, targetLibrary.Version);

                string pkgRoot;
                string libraryPath = _packageResolver.GetPackageDirectory(targetLibrary.Name, targetLibrary.Version, out pkgRoot);

                results.AddRange(GetResolvedFiles(targetLibrary.RuntimeAssemblies, targetLibraryPackage, libraryPath, pkgRoot, AssetType.Runtime));
                results.AddRange(GetResolvedFiles(targetLibrary.NativeLibraries, targetLibraryPackage, libraryPath, pkgRoot, AssetType.Native));

                foreach (LockFileRuntimeTarget runtimeTarget in targetLibrary.RuntimeTargets.FilterPlaceHolderFiles())
                {
                    if (string.Equals(runtimeTarget.AssetType, "native", StringComparison.OrdinalIgnoreCase) ||
                        string.Equals(runtimeTarget.AssetType, "runtime", StringComparison.OrdinalIgnoreCase))
                    {
                        string    sourcePath = Path.Combine(libraryPath, runtimeTarget.Path);
                        AssetType _assetType = AssetType.None;
                        Enum.TryParse <AssetType>(runtimeTarget.AssetType, true, out _assetType);

                        results.Add(
                            new ResolvedFile(
                                sourcePath: sourcePath,
                                destinationSubDirectory: GetDestinationSubDirectory(sourcePath,
                                                                                    pkgRoot,
                                                                                    GetRuntimeTargetDestinationSubDirectory(runtimeTarget)),
                                package: targetLibraryPackage,
                                assetType: _assetType));
                    }
                }

                foreach (LockFileItem resourceAssembly in targetLibrary.ResourceAssemblies.FilterPlaceHolderFiles())
                {
                    string locale;
                    string sourcePath = Path.Combine(libraryPath, resourceAssembly.Path);
                    if (!resourceAssembly.Properties.TryGetValue("locale", out locale))
                    {
                        locale = null;
                    }

                    locale = GetDestinationSubDirectory(sourcePath, pkgRoot, locale);

                    results.Add(
                        new ResolvedFile(
                            sourcePath: sourcePath,
                            destinationSubDirectory: locale,
                            package: targetLibraryPackage,
                            assetType: AssetType.Resources));
                }
            }

            return(results);
        }
示例#2
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[] { }));
        }
示例#3
0
        public IEnumerable <ResolvedFile> Resolve(ProjectContext projectContext)
        {
            List <ResolvedFile> results = new List <ResolvedFile>();

            foreach (LockFileTargetLibrary targetLibrary in projectContext.GetRuntimeLibraries(_privateAssetPackageIds))
            {
                if (targetLibrary.Type != "package")
                {
                    continue;
                }

                string libraryPath = _packageResolver.GetPackageDirectory(targetLibrary.Name, targetLibrary.Version);

                results.AddRange(GetResolvedFiles(targetLibrary.RuntimeAssemblies, libraryPath));
                results.AddRange(GetResolvedFiles(targetLibrary.NativeLibraries, libraryPath));

                foreach (LockFileRuntimeTarget runtimeTarget in targetLibrary.RuntimeTargets.FilterPlaceHolderFiles())
                {
                    if (string.Equals(runtimeTarget.AssetType, "native", StringComparison.OrdinalIgnoreCase) ||
                        string.Equals(runtimeTarget.AssetType, "runtime", StringComparison.OrdinalIgnoreCase))
                    {
                        results.Add(
                            new ResolvedFile(
                                sourcePath: Path.Combine(libraryPath, runtimeTarget.Path),
                                destinationSubDirectory: GetRuntimeTargetDestinationSubDirectory(runtimeTarget)));
                    }
                }

                foreach (LockFileItem resourceAssembly in targetLibrary.ResourceAssemblies.FilterPlaceHolderFiles())
                {
                    string locale;
                    if (!resourceAssembly.Properties.TryGetValue("locale", out locale))
                    {
                        locale = null;
                    }

                    results.Add(
                        new ResolvedFile(
                            sourcePath: Path.Combine(libraryPath, resourceAssembly.Path),
                            destinationSubDirectory: locale));
                }
            }

            return(results);
        }
        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[] { }));
        }