Пример #1
0
        public static async Task InstallFromFile(string file, string packagesFolder, CancellationToken token)
        {
            using (Stream stream = File.OpenRead(file))
            {
                var reader          = new PackageArchiveReader(stream, leaveStreamOpen: true);
                var packageIdentity = reader.GetIdentity();
                reader.Dispose();

                stream.Seek(0, SeekOrigin.Begin);

                await InstallFromStream(Task.FromResult(stream), packageIdentity, packagesFolder, token);
            }
        }
        private async Task <bool> ExecuteAsync(CancellationToken cancellationToken)
        {
            using (Stream stream = File.OpenRead(PackageFile))
            {
                var reader          = new PackageArchiveReader(stream, leaveStreamOpen: true);
                var packageIdentity = reader.GetIdentity();
                reader.Dispose();

                stream.Seek(0, SeekOrigin.Begin);

                await
                InstallFromStream(ThreadingTask.FromResult(stream), packageIdentity, PackagesFolder,
                                  cancellationToken);
            }
            return(true);
        }
Пример #3
0
        private async Task<bool> ExecuteAsync(CancellationToken cancellationToken)
        {
            using (Stream stream = File.OpenRead(PackageFile))
            {
                var reader = new PackageArchiveReader(stream, leaveStreamOpen: true);
                var packageIdentity = reader.GetIdentity();
                reader.Dispose();

                stream.Seek(0, SeekOrigin.Begin);

                await
                    InstallFromStream(ThreadingTask.FromResult(stream), packageIdentity, PackagesFolder,
                        cancellationToken);
            }
            return true;
        }
Пример #4
0
 public void Dispose()
 {
     _reader.Dispose();
 }
Пример #5
0
 protected override void Dispose(bool disposing) => _packageReader?.Dispose();
 public virtual void Dispose()
 {
     _reader?.Dispose();
 }
Пример #7
0
        public virtual async Task <IEnumerable <Assembly> > LoadAssembliesFromNuGetPackageAsync(string nupkgFile)
        {
            var fullPath = Path.GetFullPath(nupkgFile).ToLower();

            if (m_LoadedPackageAssemblies.ContainsKey(fullPath))
            {
                if (m_LoadedPackageAssemblies[fullPath].All(d => d.Assembly.IsAlive))
                {
                    return(m_LoadedPackageAssemblies[fullPath].Select(d => d.Assembly.Target).Cast <Assembly>());
                }

                m_LoadedPackageAssemblies.Remove(fullPath);
            }

            List <CachedNuGetAssembly> assemblies = new List <CachedNuGetAssembly>();

            var packageReader = new PackageArchiveReader(nupkgFile);
            var identity      = await packageReader.GetIdentityAsync(CancellationToken.None);

            using (var cache = new SourceCacheContext())
            {
                var dependencies = await GetDependenciesAsync(identity, cache);

                foreach (var dependency in dependencies.Where(d => !d.Id.Equals(identity.Id)))
                {
                    var nupkg = GetNugetPackageFile(dependency);
                    if (!File.Exists(nupkg))
                    {
                        var latestInstalledVersion = await GetLatestPackageIdentityAsync(dependency.Id);

                        if (latestInstalledVersion == null)
                        {
                            Logger.LogWarning("Failed to resolve: " + dependency.Id);
                            continue;
                        }

                        nupkg = GetNugetPackageFile(latestInstalledVersion);
                    }

                    await LoadAssembliesFromNuGetPackageAsync(nupkg);
                }
            }

            var libItems = packageReader.GetLibItems().ToList();
            var nearest  = m_FrameworkReducer.GetNearest(m_CurrentFramework, libItems.Select(x => x.TargetFramework));

            foreach (var file in libItems.Where(x => x.TargetFramework.Equals(nearest)))
            {
                foreach (var item in file.Items)
                {
                    if (!item.EndsWith(".dll"))
                    {
                        continue;
                    }

                    var entry = packageReader.GetEntry(item);
                    using var stream = entry.Open();
                    var ms = new MemoryStream();
                    await stream.CopyToAsync(ms);

                    try
                    {
                        var asm = Assembly.Load(ms.ToArray());

                        var name          = GetVersionIndependentName(asm.FullName, out string extractedVersion);
                        var parsedVersion = new Version(extractedVersion);

                        assemblies.Add(new CachedNuGetAssembly
                        {
                            Assembly     = new WeakReference(asm),
                            AssemblyName = name,
                            Version      = parsedVersion
                        });
                    }
                    catch (Exception ex)
                    {
                        Logger.LogError("Failed to load assembly: " + item);
                        Logger.LogError(ex.ToString());
                    }
                    finally
                    {
                        ms.Close();
                        stream.Close();
                    }
                }
            }

            m_LoadedPackageAssemblies.Add(fullPath, assemblies);
            packageReader.Dispose();
            return(assemblies.Select(d => d.Assembly.Target).Cast <Assembly>());
        }
Пример #8
0
 public void Dispose()
 {
     packageArchiveReader.Dispose();
 }