public void Save(Stream stream) { // Make sure we're saving a valid package id PackageIdValidator.ValidatePackageId(Id); // Throw if the package doesn't contain any dependencies nor content if (!Files.Any() && !DependencySets.SelectMany(d => d.Dependencies).Any() && !FrameworkAssemblies.Any()) { // TODO: Resources throw new InvalidOperationException("NuGetResources.CannotCreateEmptyPackage"); } if (!ValidateSpecialVersionLength(Version)) { // TODO: Resources throw new InvalidOperationException("NuGetResources.SemVerSpecialVersionTooLong"); } ValidateDependencySets(Version, DependencySets); ValidateReferenceAssemblies(Files, PackageAssemblyReferences); using (var package = new ZipArchive(stream, ZipArchiveMode.Create)) { // Validate and write the manifest WriteManifest(package, ManifestVersionUtility.DefaultVersion); // Write the files to the package var extensions = WriteFiles(package); extensions.Add("nuspec"); WriteOpcContentTypes(package, extensions); } }
public void Save(Stream stream) { // Make sure we're saving a valid package id PackageIdValidator.ValidatePackageId(Id); // Throw if the package doesn't contain any dependencies nor content if (!Files.Any() && !DependencySets.SelectMany(d => d.Dependencies).Any() && !FrameworkReferences.Any()) { throw new InvalidOperationException(NuGetResources.CannotCreateEmptyPackage); } if (!ValidateSpecialVersionLength(Version)) { throw new InvalidOperationException(NuGetResources.SemVerSpecialVersionTooLong); } ValidateDependencySets(Version, DependencySets); ValidateReferenceAssemblies(Files, PackageAssemblyReferences); if (PlatformHelper.IsMono) { #if NET45 // Mono's zip implementation isn't complete as yet using (var package = System.IO.Packaging.Package.Open(stream, FileMode.Create)) { // Validate and write the manifest WriteManifest(package, DetermineMinimumSchemaVersion(Files)); // Write the files to the package WriteFiles(package); // Copy the metadata properties back to the package package.PackageProperties.Creator = String.Join(",", Authors); package.PackageProperties.Description = Description; package.PackageProperties.Identifier = Id; package.PackageProperties.Version = Version.ToString(); package.PackageProperties.Language = Language; package.PackageProperties.Keywords = ((IPackageMetadata)this).Tags; package.PackageProperties.Title = Title; package.PackageProperties.LastModifiedBy = CreatorInfo(); } #endif } else { using (var package = new ZipArchive(stream, ZipArchiveMode.Update)) { // Validate and write the manifest WriteManifest(package, DetermineMinimumSchemaVersion(Files)); // Write the files to the package var extensions = WriteFiles(package); extensions.Add("nuspec"); WriteOpcContentTypes(package, extensions); } } }
public void Save(Stream stream) { // Make sure we're saving a valid package id PackageIdValidator.ValidatePackageId(Id); // Throw if the package doesn't contain any dependencies nor content if (!Files.Any() && !DependencySets.SelectMany(d => d.Dependencies).Any() && !FrameworkReferences.Any()) { throw new InvalidOperationException(NuGetResources.CannotCreateEmptyPackage); } if (!ValidateSpecialVersionLength(Version)) { throw new InvalidOperationException(NuGetResources.SemVerSpecialVersionTooLong); } ValidateDependencySets(Version, DependencySets); ValidateReferenceAssemblies(Files, PackageAssemblyReferences); bool requiresV4TargetFrameworkSchema = RequiresV4TargetFrameworkSchema(Files); using (Package package = Package.Open(stream, FileMode.Create)) { // Validate and write the manifest WriteManifest(package, requiresV4TargetFrameworkSchema ? ManifestVersionUtility.TargetFrameworkSupportVersion : ManifestVersionUtility.DefaultVersion); // Write the files to the package WriteFiles(package); // Copy the metadata properties back to the package package.PackageProperties.Creator = String.Join(",", Authors); package.PackageProperties.Description = Description; package.PackageProperties.Identifier = Id; package.PackageProperties.Version = Version.ToString(); package.PackageProperties.Language = Language; package.PackageProperties.Keywords = ((IPackageMetadata)this).Tags; package.PackageProperties.Title = Title; } }