Esempio n. 1
0
 private static IEnumerable <BuildAssembly> LoadAssemblies(string version, string packagesDir, string srcRoot)
 {
     if (version == "unstable")
     {
         return(from package in packages
                from framework in unstableFrameworks
                let file = $"{package}.dll"
                           select BuildAssembly.Load(framework, file, Path.Combine(srcRoot, package, "bin", "Debug", framework, file)));
     }
     else
     {
         return(packages
                .Select(p => Path.Combine(packagesDir, $"{p}-{version}.nupkg"))
                .Where(file => File.Exists(file))
                .Select(file => NuGetPackage.Load(file))
                .SelectMany(pkg => pkg.Assemblies));
     }
 }
Esempio n. 2
0
        public static NuGetPackage Load(string file)
        {
            XDocument manifest   = null;
            var       assemblies = new List <BuildAssembly>();

            using (var zip = ZipArchive.Open(file))
            {
                foreach (var entry in zip.Entries)
                {
                    if (entry.Key.EndsWith(".nuspec"))
                    {
                        using (var stream = entry.OpenEntryStream())
                        {
                            manifest = XDocument.Load(stream);
                        }
                    }
                    else if (entry.Key.StartsWith("lib/") && entry.Key.EndsWith(".dll"))
                    {
                        var    path            = entry.Key.Substring(4);
                        string targetFramework = Path.GetDirectoryName(path);
                        // Simplify the world somewhat...
                        if (targetFramework.StartsWith("portable-"))
                        {
                            targetFramework = "PCL";
                        }
                        var assemblyFile = Path.GetFileName(path);
                        using (var stream = entry.OpenEntryStream())
                        {
                            // Mono.Cecil requires the stream to be seekable. It's simplest
                            // just to copy the whole DLL to a MemoryStream and pass that to Cecil.
                            var ms = new MemoryStream();
                            stream.CopyTo(ms);
                            ms.Position = 0;
                            assemblies.Add(BuildAssembly.Load(targetFramework, assemblyFile, ms));
                        }
                    }
                }
            }
            return(new NuGetPackage(file, manifest, assemblies));
        }