Beispiel #1
0
 private Package(
     string id,
     string normalizedVersion,
     string fullVersion,
     ReadOnlyCollection <byte> nupkgBytes,
     PackageProperties properties)
 {
     Id = id ?? throw new ArgumentNullException(nameof(id));
     NormalizedVersion = normalizedVersion ?? throw new ArgumentNullException(nameof(normalizedVersion));
     FullVersion       = fullVersion ?? throw new ArgumentNullException(nameof(fullVersion));
     NupkgBytes        = nupkgBytes ?? throw new ArgumentNullException(nameof(nupkgBytes));
     Properties        = properties;
 }
Beispiel #2
0
        public static Package Create(string path, PackageProperties packageProperties)
        {
            var byteArray  = File.ReadAllBytes(path);
            var nupkgBytes = Array.AsReadOnly(byteArray);

            using (var packageStream = new MemoryStream(byteArray))
                using (var packageArchiveReader = new PackageArchiveReader(packageStream))
                {
                    return(new Package(
                               packageArchiveReader.NuspecReader.GetId(),
                               packageArchiveReader.NuspecReader.GetVersion().ToNormalizedString(),
                               packageArchiveReader.NuspecReader.GetVersion().ToFullString(),
                               nupkgBytes,
                               packageProperties));
                }
        }
Beispiel #3
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));
        }