Ejemplo n.º 1
0
        public Task RunAsync()
        {
            using (var fs = new FileStream(_options.ReferencePath, FileMode.Create, FileAccess.Write))
                using (var zip = new ZipArchive(fs, ZipArchiveMode.Create))
                {
                    foreach (var profile in _provider.SupportedProfiles)
                    {
                        try
                        {
                            _writer.WriteLine($"Adding reference assembly for: {profile}");

                            foreach (var path in _provider.GetReferenceAssemblyPath(profile))
                            {
                                foreach (var item in Directory.EnumerateFiles(path, "*.dll", SearchOption.TopDirectoryOnly))
                                {
                                    var name = Path.Combine(profile, Path.GetFileName(item));

                                    zip.CreateEntryFromFile(item, name, CompressionLevel.Optimal);
                                }
                            }
                        }
                        catch (DirectoryNotFoundException)
                        {
                            _writer.WriteLine($"Could not find {profile}");
                        }
                    }
                }

            return(Task.CompletedTask);
        }
        private HostEnvironment CreateHostEnvironment(NameTable nameTable, NuGetFramework framework)
        {
            void UnableToResolve(object sender, UnresolvedReference <IUnit, AssemblyIdentity> e)
            {
                Trace.TraceError("Unable to resolve assembly '{0}' referenced by the implementation assembly '{1}'.", e.Unresolved, e.Referrer);
            }

            var host = new HostEnvironment(nameTable)
            {
                ResolveAgainstRunningFramework = true,
                UnifyToLibPath     = s_unifyToLibPaths,
                LoadErrorTreatment = ErrorTreatment.TreatAsWarning
            };

            host.UnableToResolve += new EventHandler <UnresolvedReference <IUnit, AssemblyIdentity> >(UnableToResolve);

            foreach (var path in _referenceAssemblyProvider.GetReferenceAssemblyPath(framework.HasProfile ? framework.Profile : framework.GetShortFolderName()))
            {
                host.AddLibPath(path);
            }

            return(host);
        }