Exemple #1
0
        public void Initialize(IEnumerable <LibraryDescription> packages, FrameworkName targetFramework, string runtimeIdentifier)
        {
            Dependencies = packages;

            var cacheResolvers  = GetCacheResolvers();
            var defaultResolver = new DefaultPackagePathResolver(_repository.RepositoryRoot);

            foreach (var dependency in packages)
            {
                var packageInfo = _repository.FindPackagesById(dependency.Identity.Name)
                                  .FirstOrDefault(p => p.Version == dependency.Identity.Version);

                if (packageInfo == null)
                {
                    continue;
                }

                string packagePath = ResolvePackagePath(defaultResolver, cacheResolvers, packageInfo);

                // If the package path doesn't exist then mark this dependency as unresolved
                if (!Directory.Exists(packagePath))
                {
                    dependency.Resolved = false;
                    continue;
                }

                dependency.Path = packagePath;

                var packageDescription = new PackageDescription
                {
                    Library = dependency,
                    Package = packageInfo
                };

                _packageDescriptions[packageInfo.Id] = packageDescription;

                if (Servicing.Breadcrumbs.Instance.IsPackageServiceable(packageDescription.Package))
                {
                    Servicing.Breadcrumbs.Instance.AddBreadcrumb(packageInfo.Id, packageInfo.Version);
                }

                var lookupKey = Tuple.Create(runtimeIdentifier, targetFramework, packageInfo.LockFileLibrary.Name);

                if (_lookup == null)
                {
                    continue;
                }

                LockFileTargetLibrary targetLibrary;
                if (!_lookup.TryGetValue(lookupKey, out targetLibrary))
                {
                    continue;
                }

                var assemblies = new List <string>();

                foreach (var runtimeAssemblyPath in targetLibrary.RuntimeAssemblies)
                {
                    if (IsPlaceholderFile(runtimeAssemblyPath))
                    {
                        continue;
                    }

                    // Fix up the slashes to match the platform
                    var assemblyPath = runtimeAssemblyPath.Path.Replace('/', Path.DirectorySeparatorChar);
                    var name         = Path.GetFileNameWithoutExtension(assemblyPath);
                    var path         = Path.Combine(dependency.Path, assemblyPath);
                    var assemblyName = new AssemblyName(name);

                    string replacementPath;
                    if (Servicing.ServicingTable.TryGetReplacement(
                            packageInfo.Id,
                            packageInfo.Version,
                            assemblyPath,
                            out replacementPath))
                    {
                        _packageAssemblyLookup[assemblyName] = new PackageAssembly()
                        {
                            Path         = replacementPath,
                            RelativePath = assemblyPath,
                            Library      = dependency
                        };
                    }
                    else
                    {
                        _packageAssemblyLookup[assemblyName] = new PackageAssembly()
                        {
                            Path         = path,
                            RelativePath = assemblyPath,
                            Library      = dependency
                        };
                    }

                    assemblies.Add(name);
                }

                dependency.LoadableAssemblies = assemblies;
            }
        }
        public void Initialize(IEnumerable<LibraryDescription> packages, FrameworkName targetFramework)
        {
            Dependencies = packages;

            var cacheResolvers = GetCacheResolvers();
            var defaultResolver = new DefaultPackagePathResolver(_repository.RepositoryRoot);

            foreach (var dependency in packages)
            {
                var packageInfo = _repository.FindPackagesById(dependency.Identity.Name)
                    .FirstOrDefault(p => p.Version == dependency.Identity.Version);

                if (packageInfo == null)
                {
                    continue;
                }

                string packagePath = ResolvePackagePath(defaultResolver, cacheResolvers, packageInfo);

                // If the package path doesn't exist then mark this dependency as unresolved
                if (!Directory.Exists(packagePath))
                {
                    dependency.Resolved = false;
                    continue;
                }

                dependency.Path = packagePath;

                var packageDescription = new PackageDescription
                {
                    Library = dependency,
                    Package = packageInfo
                };

                _packageDescriptions[packageInfo.Id] = packageDescription;

                if (Servicing.Breadcrumbs.Instance.IsPackageServiceable(packageDescription.Package))
                {
                    Servicing.Breadcrumbs.Instance.AddBreadcrumb(packageInfo.Id, packageInfo.Version);
                }

                var group = packageInfo.LockFileLibrary.FrameworkGroups.FirstOrDefault(g => g.TargetFramework == targetFramework);
                if (group == null)
                {
                    continue;
                }

                var assemblies = new List<string>();

                foreach (var assemblyPath in group.RuntimeAssemblies)
                {
                    var name = Path.GetFileNameWithoutExtension(assemblyPath);
                    var path = Path.Combine(dependency.Path, assemblyPath);

                    string replacementPath;
                    if (Servicing.ServicingTable.TryGetReplacement(
                        packageInfo.Id,
                        packageInfo.Version,
                        assemblyPath,
                        out replacementPath))
                    {
                        _packageAssemblyLookup[name] = new PackageAssembly()
                        {
                            Path = replacementPath,
                            RelativePath = assemblyPath,
                            Library = dependency
                        };
                    }
                    else
                    {
                        _packageAssemblyLookup[name] = new PackageAssembly()
                        {
                            Path = path,
                            RelativePath = assemblyPath,
                            Library = dependency
                        };
                    }

                    assemblies.Add(name);
                }

                dependency.LoadableAssemblies = assemblies;
            }
        }
        public void Initialize(IEnumerable <LibraryDescription> packages, FrameworkName targetFramework)
        {
            Dependencies = packages;

            var cacheResolvers  = GetCacheResolvers();
            var defaultResolver = new DefaultPackagePathResolver(_repository.RepositoryRoot);

            foreach (var dependency in packages)
            {
                var packageInfo = _repository.FindPackagesById(dependency.Identity.Name)
                                  .FirstOrDefault(p => p.Version == dependency.Identity.Version);

                if (packageInfo == null)
                {
                    continue;
                }

                string packagePath = ResolvePackagePath(defaultResolver, cacheResolvers, packageInfo);

                // If the package path doesn't exist then mark this dependency as unresolved
                if (!Directory.Exists(packagePath))
                {
                    dependency.Resolved = false;
                    continue;
                }

                dependency.Path = packagePath;

                var packageDescription = new PackageDescription
                {
                    Library = dependency,
                    Package = packageInfo
                };

                _packageDescriptions[packageInfo.Id] = packageDescription;

                if (Servicing.Breadcrumbs.Instance.IsPackageServiceable(packageDescription.Package))
                {
                    Servicing.Breadcrumbs.Instance.AddBreadcrumb(packageInfo.Id, packageInfo.Version);
                }

                var group = packageInfo.LockFileLibrary.FrameworkGroups.FirstOrDefault(g => g.TargetFramework == targetFramework);
                if (group == null)
                {
                    continue;
                }

                var assemblies = new List <string>();

                foreach (var assemblyPath in group.RuntimeAssemblies)
                {
                    var name = Path.GetFileNameWithoutExtension(assemblyPath);
                    var path = Path.Combine(dependency.Path, assemblyPath);

                    string replacementPath;
                    if (Servicing.ServicingTable.TryGetReplacement(
                            packageInfo.Id,
                            packageInfo.Version,
                            assemblyPath,
                            out replacementPath))
                    {
                        _packageAssemblyLookup[name] = new PackageAssembly()
                        {
                            Path         = replacementPath,
                            RelativePath = assemblyPath,
                            Library      = dependency
                        };
                    }
                    else
                    {
                        _packageAssemblyLookup[name] = new PackageAssembly()
                        {
                            Path         = path,
                            RelativePath = assemblyPath,
                            Library      = dependency
                        };
                    }

                    assemblies.Add(name);
                }

                dependency.LoadableAssemblies = assemblies;
            }
        }