Table of Contents

Class PackageReaderBase

Namespace
NuGet.Packaging
Assembly
Chocolatey.NuGet.Packaging.dll

Abstract class that both the zip and folder package readers extend This class contains the path conventions for both zip and folder readers

public abstract class PackageReaderBase : IPackageCoreReader, IPackageContentReader, IAsyncPackageCoreReader, IAsyncPackageContentReader, ISignedPackageReader, IDisposable
Inheritance
PackageReaderBase
Implements
Derived
Inherited Members
Extension Methods

Constructors

PackageReaderBase(IFrameworkNameProvider)

Instantiates a new PackageReaderBase class.

public PackageReaderBase(IFrameworkNameProvider frameworkProvider)

Parameters

frameworkProvider IFrameworkNameProvider

A framework mapping provider.

Exceptions

ArgumentNullException

Thrown if frameworkProvider is null.

PackageReaderBase(IFrameworkNameProvider, IFrameworkCompatibilityProvider)

Instantiates a new PackageReaderBase class.

public PackageReaderBase(IFrameworkNameProvider frameworkProvider, IFrameworkCompatibilityProvider compatibilityProvider)

Parameters

frameworkProvider IFrameworkNameProvider

A framework mapping provider.

compatibilityProvider IFrameworkCompatibilityProvider

A framework compatibility provider.

Exceptions

ArgumentNullException

Thrown if frameworkProvider is null.

ArgumentNullException

Thrown if compatibilityProvider is null.

Properties

CompatibilityProvider

protected IFrameworkCompatibilityProvider CompatibilityProvider { get; set; }

Property Value

IFrameworkCompatibilityProvider

FrameworkProvider

protected IFrameworkNameProvider FrameworkProvider { get; set; }

Property Value

IFrameworkNameProvider

NuspecReader

Nuspec reader

public virtual NuspecReader NuspecReader { get; }

Property Value

NuspecReader

Methods

CanVerifySignedPackages(SignedPackageVerifierSettings)

Indicates if the the ISignedPackageReader instance can verify signed packages.

public abstract bool CanVerifySignedPackages(SignedPackageVerifierSettings verifierSettings)

Parameters

verifierSettings SignedPackageVerifierSettings

Package verification settings. Include information about what is allowed.

Returns

bool

Exceptions

SignatureException

if the ISignedPackageReader does not support signed packages

CopyFiles(string, IEnumerable<string>, ExtractPackageFileDelegate, ILogger, CancellationToken)

Copies files from a package to a new location.

public abstract IEnumerable<string> CopyFiles(string destination, IEnumerable<string> packageFiles, ExtractPackageFileDelegate extractFile, ILogger logger, CancellationToken token)

Parameters

destination string

The destination folder path.

packageFiles IEnumerable<string>

The package files to copy.

extractFile ExtractPackageFileDelegate

A package file extraction delegate.

logger ILogger

A logger.

token CancellationToken

A cancellation token.

Returns

IEnumerable<string>

An enumerable of paths of files copied to the destination.

CopyFilesAsync(string, IEnumerable<string>, ExtractPackageFileDelegate, ILogger, CancellationToken)

Asynchronously copies files from a package to a new location.

public virtual Task<IEnumerable<string>> CopyFilesAsync(string destination, IEnumerable<string> packageFiles, ExtractPackageFileDelegate extractFile, ILogger logger, CancellationToken cancellationToken)

Parameters

destination string

The destination path to copy to.

packageFiles IEnumerable<string>

The package files to copy.

extractFile ExtractPackageFileDelegate

A package file extraction delegate.

logger ILogger

A logger.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IEnumerable<string>>

A task that represents the asynchronous operation. The task result (Result) returns am IEnumerable<T> for the copied file paths.

Exceptions

OperationCanceledException

Thrown if cancellationToken is cancelled.

CopyNupkgAsync(string, CancellationToken)

public virtual Task<string> CopyNupkgAsync(string nupkgFilePath, CancellationToken cancellationToken)

Parameters

nupkgFilePath string
cancellationToken CancellationToken

Returns

Task<string>

Dispose()

public void Dispose()

Dispose(bool)

protected abstract void Dispose(bool disposing)

Parameters

disposing bool

GetArchiveHashAsync(HashAlgorithmName, CancellationToken)

Gets the hash of an archive to be embedded in the package signature.

public abstract Task<byte[]> GetArchiveHashAsync(HashAlgorithmName hashAlgorithm, CancellationToken token)

Parameters

hashAlgorithm HashAlgorithmName
token CancellationToken

Returns

Task<byte[]>

GetBuildItems()

Returns all items under the build folder.

public virtual IEnumerable<FrameworkSpecificGroup> GetBuildItems()

Returns

IEnumerable<FrameworkSpecificGroup>

GetBuildItemsAsync(CancellationToken)

Asynchronously returns all items under the build folder.

public virtual Task<IEnumerable<FrameworkSpecificGroup>> GetBuildItemsAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IEnumerable<FrameworkSpecificGroup>>

A task that represents the asynchronous operation. The task result (Result) returns an IEnumerable<T>.

GetContentHash(CancellationToken, Func<string>)

Get contenthash for a package.

public abstract string GetContentHash(CancellationToken token, Func<string> GetUnsignedPackageHash = null)

Parameters

token CancellationToken
GetUnsignedPackageHash Func<string>

Returns

string

GetContentItems()

Returns all items found in the content folder.

public virtual IEnumerable<FrameworkSpecificGroup> GetContentItems()

Returns

IEnumerable<FrameworkSpecificGroup>

Remarks

Some legacy behavior has been dropped here due to the mix of content folders and target framework folders here.

GetContentItemsAsync(CancellationToken)

Asynchronously returns all items found in the content folder.

public virtual Task<IEnumerable<FrameworkSpecificGroup>> GetContentItemsAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IEnumerable<FrameworkSpecificGroup>>

A task that represents the asynchronous operation. The task result (Result) returns an IEnumerable<T>.

Remarks

Some legacy behavior has been dropped here due to the mix of content folders and target framework folders here.

GetDevelopmentDependency()

public virtual bool GetDevelopmentDependency()

Returns

bool

GetDevelopmentDependencyAsync(CancellationToken)

public virtual Task<bool> GetDevelopmentDependencyAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task<bool>

GetFileGroups(string)

protected IEnumerable<FrameworkSpecificGroup> GetFileGroups(string folder)

Parameters

folder string

Returns

IEnumerable<FrameworkSpecificGroup>

GetFiles()

Gets all files in the package.

public abstract IEnumerable<string> GetFiles()

Returns

IEnumerable<string>

An enumerable of files in the package.

GetFiles(string)

Gets files in a folder in the package.

public abstract IEnumerable<string> GetFiles(string folder)

Parameters

folder string

Folder path

Returns

IEnumerable<string>

An enumerable of files under specified folder.

GetFilesAsync(string, CancellationToken)

Asynchronously gets files in a folder in the package.

public virtual Task<IEnumerable<string>> GetFilesAsync(string folder, CancellationToken cancellationToken)

Parameters

folder string

A folder path in the package.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IEnumerable<string>>

A task that represents the asynchronous operation. The task result (Result) returns an IEnumerable<T> for files under the specified folder.

Exceptions

OperationCanceledException

Thrown if cancellationToken is cancelled.

GetFilesAsync(CancellationToken)

Asynchronously gets all files in the package.

public virtual Task<IEnumerable<string>> GetFilesAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IEnumerable<string>>

A task that represents the asynchronous operation. The task result (Result) returns an IEnumerable<T>.

Exceptions

OperationCanceledException

Thrown if cancellationToken is cancelled.

GetFrameworkFromPath(string, bool)

protected NuGetFramework GetFrameworkFromPath(string path, bool allowSubFolders = false)

Parameters

path string
allowSubFolders bool

Returns

NuGetFramework

GetFrameworkItems()

Returns all framework references found in the nuspec.

public virtual IEnumerable<FrameworkSpecificGroup> GetFrameworkItems()

Returns

IEnumerable<FrameworkSpecificGroup>

GetFrameworkItemsAsync(CancellationToken)

Asynchronously returns all framework references found in the nuspec.

public virtual Task<IEnumerable<FrameworkSpecificGroup>> GetFrameworkItemsAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IEnumerable<FrameworkSpecificGroup>>

A task that represents the asynchronous operation. The task result (Result) returns an IEnumerable<T>.

GetIdentity()

Gets the package identity.

public virtual PackageIdentity GetIdentity()

Returns

PackageIdentity

A package identity.

GetIdentityAsync(CancellationToken)

Asynchronously gets the identity of the package.

public virtual Task<PackageIdentity> GetIdentityAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<PackageIdentity>

A task that represents the asynchronous operation. The task result (Result) returns a PackageIdentity.

Exceptions

OperationCanceledException

Thrown if cancellationToken is cancelled.

GetItems(string)

public virtual IEnumerable<FrameworkSpecificGroup> GetItems(string folderName)

Parameters

folderName string

Returns

IEnumerable<FrameworkSpecificGroup>

GetItemsAsync(string, CancellationToken)

public virtual Task<IEnumerable<FrameworkSpecificGroup>> GetItemsAsync(string folderName, CancellationToken cancellationToken)

Parameters

folderName string
cancellationToken CancellationToken

Returns

Task<IEnumerable<FrameworkSpecificGroup>>

GetLibItems()

Returns all lib items without any filtering. Use GetReferenceItems for the filtered list.

public virtual IEnumerable<FrameworkSpecificGroup> GetLibItems()

Returns

IEnumerable<FrameworkSpecificGroup>

GetLibItemsAsync(CancellationToken)

Asynchronously returns all lib items without any filtering.

public virtual Task<IEnumerable<FrameworkSpecificGroup>> GetLibItemsAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IEnumerable<FrameworkSpecificGroup>>

A task that represents the asynchronous operation. The task result (Result) returns an IEnumerable<T>.

Remarks

Use GetReferenceItemsAsync(...) for the filtered list.

GetMinClientVersion()

Gets the minimum client version needed to consume the package.

public virtual NuGetVersion GetMinClientVersion()

Returns

NuGetVersion

A NuGet version.

GetMinClientVersionAsync(CancellationToken)

Asynchronously gets the minimum client version needed to consume the package.

public virtual Task<NuGetVersion> GetMinClientVersionAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<NuGetVersion>

A task that represents the asynchronous operation. The task result (Result) returns a NuGet.Versioning.NuGetVersion.

Exceptions

OperationCanceledException

Thrown if cancellationToken is cancelled.

GetNuspec()

Gets a nuspec stream.

public virtual Stream GetNuspec()

Returns

Stream

A stream for the nuspec.

GetNuspecAsync(CancellationToken)

Asynchronously gets a nuspec stream.

public virtual Task<Stream> GetNuspecAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Stream>

A task that represents the asynchronous operation. The task result (Result) returns a Stream.

Exceptions

OperationCanceledException

Thrown if cancellationToken is cancelled.

GetNuspecFile()

Gets a nuspec file path.

public virtual string GetNuspecFile()

Returns

string

The nuspec file path.

GetNuspecFile(IEnumerable<string>)

protected static string GetNuspecFile(IEnumerable<string> files)

Parameters

files IEnumerable<string>

Returns

string

GetNuspecFileAsync(CancellationToken)

Asynchronously gets a nuspec file path.

public virtual Task<string> GetNuspecFileAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<string>

A task that represents the asynchronous operation. The task result (Result) returns a string representing the nuspec file path.

Exceptions

OperationCanceledException

Thrown if cancellationToken is cancelled.

GetNuspecReaderAsync(CancellationToken)

public virtual Task<NuspecReader> GetNuspecReaderAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task<NuspecReader>

GetPackageDependencies()

Returns package dependencies.

public virtual IEnumerable<PackageDependencyGroup> GetPackageDependencies()

Returns

IEnumerable<PackageDependencyGroup>

GetPackageDependenciesAsync(CancellationToken)

Asynchronously returns package dependencies.

public virtual Task<IEnumerable<PackageDependencyGroup>> GetPackageDependenciesAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IEnumerable<PackageDependencyGroup>>

A task that represents the asynchronous operation. The task result (Result) returns an IEnumerable<T>.

GetPackageTypes()

Gets zero or more package types from the .nuspec.

public virtual IReadOnlyList<PackageType> GetPackageTypes()

Returns

IReadOnlyList<PackageType>

A readonly list of package types.

GetPackageTypesAsync(CancellationToken)

Asynchronously gets zero or more package types from the .nuspec.

public virtual Task<IReadOnlyList<PackageType>> GetPackageTypesAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IReadOnlyList<PackageType>>

A task that represents the asynchronous operation. The task result (Result) returns an IReadOnlyList<T>.

Exceptions

OperationCanceledException

Thrown if cancellationToken is cancelled.

GetPrimarySignatureAsync(CancellationToken)

Get package signature.

public abstract Task<PrimarySignature> GetPrimarySignatureAsync(CancellationToken token)

Parameters

token CancellationToken

Returns

Task<PrimarySignature>

Remarks

Returns a null if the package is unsigned.

GetReferenceItems()

Returns lib items + filtering based on the nuspec and other NuGet rules.

public virtual IEnumerable<FrameworkSpecificGroup> GetReferenceItems()

Returns

IEnumerable<FrameworkSpecificGroup>

GetReferenceItemsAsync(CancellationToken)

Asynchronously returns lib items + filtering based on the nuspec and other NuGet rules.

public virtual Task<IEnumerable<FrameworkSpecificGroup>> GetReferenceItemsAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IEnumerable<FrameworkSpecificGroup>>

A task that represents the asynchronous operation. The task result (Result) returns an IEnumerable<T>.

GetStream(string)

Gets a file stream from the package.

public abstract Stream GetStream(string path)

Parameters

path string

Returns

Stream

A stream for a file in the package.

GetStreamAsync(string, CancellationToken)

Asynchronously returns a file stream from the package.

public virtual Task<Stream> GetStreamAsync(string path, CancellationToken cancellationToken)

Parameters

path string

The file path in the package.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Stream>

A task that represents the asynchronous operation. The task result (Result) returns a Stream.

Exceptions

OperationCanceledException

Thrown if cancellationToken is cancelled.

GetSupportedFrameworks()

Frameworks mentioned in the package.

public virtual IEnumerable<NuGetFramework> GetSupportedFrameworks()

Returns

IEnumerable<NuGetFramework>

Remarks

This method returns the target frameworks supported for packages.config projects. For PackageReference compatibility, use ManagedCodeConventions

GetSupportedFrameworksAsync(CancellationToken)

Frameworks mentioned in the package.

public virtual Task<IEnumerable<NuGetFramework>> GetSupportedFrameworksAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task<IEnumerable<NuGetFramework>>

Remarks

This method returns the target frameworks supported for packages.config projects. For PackageReference compatibility, use ManagedCodeConventions

GetToolItems()

Returns all items under the tools folder.

public virtual IEnumerable<FrameworkSpecificGroup> GetToolItems()

Returns

IEnumerable<FrameworkSpecificGroup>

GetToolItemsAsync(CancellationToken)

Asynchronously returns all items under the tools folder.

public virtual Task<IEnumerable<FrameworkSpecificGroup>> GetToolItemsAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A cancellation token.

Returns

Task<IEnumerable<FrameworkSpecificGroup>>

A task that represents the asynchronous operation. The task result (Result) returns an IEnumerable<T>.

IsAllowedBuildFile(string, string)

only packageId.targets and packageId.props should be used from the build folder

protected static bool IsAllowedBuildFile(string packageId, string path)

Parameters

packageId string
path string

Returns

bool

IsReferenceAssembly(string)

True only for assemblies that should be added as references to msbuild projects

protected static bool IsReferenceAssembly(string path)

Parameters

path string

Returns

bool

IsServiceable()

public virtual bool IsServiceable()

Returns

bool

IsServiceableAsync(CancellationToken)

public virtual Task<bool> IsServiceableAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task<bool>

IsSignedAsync(CancellationToken)

Check if a package contains signing information.

public abstract Task<bool> IsSignedAsync(CancellationToken token)

Parameters

token CancellationToken

Returns

Task<bool>

True if the package is signed.

NormalizeDirectoryPath(string)

protected string NormalizeDirectoryPath(string path)

Parameters

path string

Returns

string

ValidateIntegrityAsync(SignatureContent, CancellationToken)

Checks for the integrity of a package

public abstract Task ValidateIntegrityAsync(SignatureContent signatureContent, CancellationToken token)

Parameters

signatureContent SignatureContent

SignatureContent with expected hash value and hash algorithm used

token CancellationToken

Returns

Task

ValidatePackageEntries(string, IEnumerable<string>, PackageIdentity)

protected static void ValidatePackageEntries(string normalizedDestination, IEnumerable<string> packageFiles, PackageIdentity packageIdentity)

Parameters

normalizedDestination string
packageFiles IEnumerable<string>
packageIdentity PackageIdentity

ValidatePackageEntry(string, string, PackageIdentity)

Validate file entry in package is not traversed outside of the expected extraction path. Eg: file entry like ../../foo.dll can get outside of the expected extraction path.

protected static void ValidatePackageEntry(string normalizedDestination, string normalizedFilePath, PackageIdentity packageIdentity)

Parameters

normalizedDestination string
normalizedFilePath string
packageIdentity PackageIdentity