private async Task SavePackageLicenseFile(Stream packageFile, Package package) { packageFile.Seek(0, SeekOrigin.Begin); using (var packageArchiveReader = new PackageArchiveReader(packageFile, leaveStreamOpen: true)) { var packageMetadata = PackageMetadata.FromNuspecReader(packageArchiveReader.GetNuspecReader(), strict: true); if (packageMetadata.LicenseMetadata == null || packageMetadata.LicenseMetadata.Type != LicenseType.File || string.IsNullOrWhiteSpace(packageMetadata.LicenseMetadata.License)) { throw new InvalidOperationException("No license file specified in the nuspec"); } var filename = packageMetadata.LicenseMetadata.License; var licenseFileEntry = packageArchiveReader.GetEntry(filename); // throws on non-existent file using (var licenseFileStream = licenseFileEntry.Open()) { await _packageFileService.SaveLicenseFileAsync(package, licenseFileStream); } } }