示例#1
0
        private static Stream InjectEmbeddedMetadata(Stream packageStream, PackageCreationContext context)
        {
            using (var archive = new ZipArchive(packageStream, ZipArchiveMode.Update, leaveOpen: true))
            {
                var    nuspecEntry = archive.GetEntry($"{context.Id}.nuspec");
                string nuspecContent;
                using (var nuspecStream = nuspecEntry.Open())
                    using (var streamReader = new StreamReader(nuspecStream))
                    {
                        nuspecContent = streamReader.ReadToEnd();
                    }

                if (context.Properties.EmbeddedIconFilename != null)
                {
                    nuspecContent = nuspecContent.Replace("</metadata>", $"  <icon>{context.Properties.EmbeddedIconFilename}</icon>\n  </metadata>");
                }

                if (context.Properties.EmbeddedReadmeFilename != null)
                {
                    nuspecContent = nuspecContent.Replace("</metadata>", $"  <readme>{context.Properties.EmbeddedReadmeFilename}</readme>\n  </metadata>");
                }

                using (var nuspecStream = nuspecEntry.Open())
                    using (var streamWriter = new StreamWriter(nuspecStream))
                    {
                        streamWriter.Write(nuspecContent);
                    }
            }

            packageStream.Seek(0, SeekOrigin.Begin);
            return(packageStream);
        }
示例#2
0
        public static Stream BuildPackageStream(PackageCreationContext context)
        {
            var packageBuilder = new PackageBuilder();

            packageBuilder.Id      = context.Id;
            packageBuilder.Version = NuGetVersion.Parse(context.FullVersion ?? context.NormalizedVersion);
            packageBuilder.Authors.Add("EndToEndTests");
            packageBuilder.Description = $"Description of {context.Id}";
            packageBuilder.Files.Add(new PhysicalPackageFile(new MemoryStream())
            {
                TargetPath = "tools/empty.txt"
            });
            packageBuilder.Files.Add(new PhysicalPackageFile(new MemoryStream())
            {
                TargetPath = $"lib/{TargetFramework.GetShortFolderName()}/_._"
            });

            if (context.DependencyGroups != null)
            {
                packageBuilder.DependencyGroups.AddRange(context.DependencyGroups);
            }

            var memoryStream = new MemoryStream();

            packageBuilder.Save(memoryStream);
            memoryStream.Position = 0;

            return(memoryStream);
        }
        public static Package Create(PackageCreationContext context)
        {
            ReadOnlyCollection <byte> nupkgBytes;

            using (var nupkgStream = TestData.BuildPackageStream(context))
            {
                var bufferStream = new MemoryStream();
                nupkgStream.CopyTo(bufferStream);
                nupkgBytes = Array.AsReadOnly(bufferStream.ToArray());
            }

            return(new Package(context.Id, context.NormalizedVersion, context.FullVersion, nupkgBytes));
        }
示例#4
0
        public static Stream BuildPackageStreamForFiles(PackageCreationContext context, IEnumerable <PhysicalPackageFile> files, bool isSymbolsPackage)
        {
            var packageBuilder = GetPackageBuilder(context, files);

            if (!isSymbolsPackage)
            {
                packageBuilder.Authors.Add("EndToEndTests");
            }
            else
            {
                packageBuilder.PackageTypes.Add(new Packaging.Core.PackageType("SymbolsPackage", Packaging.Core.PackageType.EmptyVersion));
            }

            return(GetStreamFromBuilder(packageBuilder));
        }
示例#5
0
        public static Stream BuildPackageStream(PackageCreationContext context)
        {
            var files = new List <PhysicalPackageFile>()
            {
                new PhysicalPackageFile(new MemoryStream())
                {
                    TargetPath = "tools/empty.txt"
                },
                new PhysicalPackageFile(new MemoryStream())
                {
                    TargetPath = $"lib/{TargetFramework.GetShortFolderName()}/_._"
                }
            };

            return(BuildPackageStreamForFiles(context, files, isSymbolsPackage: false));
        }
示例#6
0
        private static PackageBuilder GetPackageBuilder(PackageCreationContext context, IEnumerable <PhysicalPackageFile> files)
        {
            var packageBuilder = new PackageBuilder();

            packageBuilder.Id          = context.Id;
            packageBuilder.Version     = NuGetVersion.Parse(context.FullVersion ?? context.NormalizedVersion);
            packageBuilder.Description = $"Description of {context.Id}";
            foreach (PhysicalPackageFile file in files)
            {
                packageBuilder.Files.Add(file);
            }

            if (context.DependencyGroups != null)
            {
                packageBuilder.DependencyGroups.AddRange(context.DependencyGroups);
            }

            return(packageBuilder);
        }
示例#7
0
        public static Package Create(PackageCreationContext context, IEnumerable <string> files, PackageProperties properties)
        {
            var physicalPackageFilesList = files
                                           .Select(x => new { FileName = Path.GetFileName(x), Stream = GetMemoryStreamForFile(x) })
                                           .Select(x => new PhysicalPackageFile(x.Stream)
            {
                TargetPath = $"lib/{x.FileName}"
            });

            ReadOnlyCollection <byte> nupkgBytes;

            using (var nupkgStream = TestData.BuildPackageStreamForFiles(context, physicalPackageFilesList, properties.IsSymbolsPackage))
                using (var bufferStream = new MemoryStream())
                {
                    nupkgStream.CopyTo(bufferStream);
                    nupkgBytes = Array.AsReadOnly(bufferStream.ToArray());
                }

            return(new Package(context.Id, context.NormalizedVersion, context.FullVersion, nupkgBytes, properties));
        }
示例#8
0
        public static Stream BuildPackageStream(PackageCreationContext context)
        {
            if (context.Files == null)
            {
                context.Files = GetDefaultFiles();
            }

            if (context.Properties.EmbeddedIconFilename != null)
            {
                var extraFiles = new[]
                {
                    new AssemblyMetadataPackageFile($"Icons.{context.Properties.EmbeddedIconFilename}")
                    {
                        Path          = context.Properties.EmbeddedIconFilename,
                        EffectivePath = context.Properties.EmbeddedIconFilename,
                    }
                };
                context.Files = context.Files.Concat(extraFiles).ToList();
            }

            if (context.Properties.EmbeddedReadmeFilename != null)
            {
                var extraFiles = new[]
                {
                    new AssemblyMetadataPackageFile($"Readmes.{context.Properties.EmbeddedReadmeFilename}")
                    {
                        Path          = context.Properties.EmbeddedReadmeFilename,
                        EffectivePath = context.Properties.EmbeddedReadmeFilename,
                    }
                };
                context.Files = context.Files.Concat(extraFiles).ToList();
            }

            var packageBuilder = new PackageBuilder();

            packageBuilder.Id          = context.Id;
            packageBuilder.Version     = NuGetVersion.Parse(context.FullVersion ?? context.NormalizedVersion);
            packageBuilder.Description = $"Description of {context.Id}";

            foreach (var file in context.Files)
            {
                packageBuilder.Files.Add(file);
            }

            if (context.DependencyGroups != null)
            {
                packageBuilder.DependencyGroups.AddRange(context.DependencyGroups);
            }

            if (context.Properties != null && context.Properties.LicenseMetadata != null)
            {
                packageBuilder.LicenseMetadata = context.Properties.LicenseMetadata;
            }

            if (context.Properties != null && context.Properties.LicenseUrl != null)
            {
                packageBuilder.LicenseUrl = context.Properties.LicenseUrl;
            }

            if (context.Properties.Type == PackageType.SymbolsPackage)
            {
                packageBuilder.PackageTypes.Add(new Packaging.Core.PackageType("SymbolsPackage", Packaging.Core.PackageType.EmptyVersion));
            }
            else
            {
                packageBuilder.Authors.Add("EndToEndTests");
            }

            var packageStream = GetStreamFromBuilder(packageBuilder);

            if (context.Properties.EmbeddedIconFilename != null || context.Properties.EmbeddedReadmeFilename != null)
            {
                return(InjectEmbeddedMetadata(packageStream, context));
            }

            return(packageStream);
        }
示例#9
0
 public static Package Create(PackageCreationContext context, IEnumerable <string> files)
 {
     return(Create(context, files, new PackageProperties()));
 }