NuGetPackageValidator Class

Provides methods to validate NuGet packages against a set of rules to ensure they follow best practices and contain required metadata.

public static class NuGetPackageValidator

Example

// Validate a package with default rules
var packagePath = FullPath.FromPath("MyPackage.1.0.0.nupkg");
var result = await NuGetPackageValidator.ValidateAsync(packagePath);
if (!result.IsValid)
{
    foreach (var error in result.Errors)
    {
        Console.WriteLine($"{error.ErrorCode}: {error.Message}");
    }
}

// Validate with specific rules
var options = new NuGetPackageValidationOptions();
options.Rules.Add(NuGetPackageValidationRules.LicenseMustBeSet);
options.Rules.Add(NuGetPackageValidationRules.AuthorMustBeSet);
var customResult = await NuGetPackageValidator.ValidateAsync(packagePath, options);

Methods

NameDescription
ValidateAsync(FullPath, NuGetPackageValidationOptions, CancellationToken)Validates a NuGet package using custom validation options.
ValidateAsync(FullPath, IEnumerable<NuGetPackageValidationRule>, CancellationToken)Validates a NuGet package using a custom set of validation rules.
ValidateAsync(FullPath, CancellationToken)Validates a NuGet package using the default set of validation rules.

ValidateAsync overloads

ValidateAsync(FullPath, NuGetPackageValidationOptions, CancellationToken)

NuGetPackageValidator.cs

Validates a NuGet package using custom validation options.

net10.0

public static Task<NuGetPackageValidationResult> ValidateAsync(FullPath packagePath, NuGetPackageValidationOptions options, CancellationToken cancellationToken = default)

net11.0

public static Task<NuGetPackageValidationResult> ValidateAsync(FullPath packagePath, NuGetPackageValidationOptions options, CancellationToken cancellationToken = default)
Parameters
packagePath FullPath
The path to the NuGet package file (.nupkg) to validate.
options NuGetPackageValidationOptions
The validation options that specify which rules to apply and other configuration settings.
cancellationToken CancellationToken
A token to cancel the validation operation.
Returns

Task<NuGetPackageValidationResult> A task that represents the asynchronous validation operation. The task result contains the validation result with any errors found.

ValidateAsync(FullPath, IEnumerable<NuGetPackageValidationRule>, CancellationToken)

NuGetPackageValidator.cs

Validates a NuGet package using a custom set of validation rules.

public static Task<NuGetPackageValidationResult> ValidateAsync(FullPath packagePath, IEnumerable<NuGetPackageValidationRule> rules, CancellationToken cancellationToken = default)
Parameters
packagePath FullPath
The path to the NuGet package file (.nupkg) to validate.
rules IEnumerable<NuGetPackageValidationRule>
The collection of validation rules to apply.
cancellationToken CancellationToken
A token to cancel the validation operation.
Returns

Task<NuGetPackageValidationResult> A task that represents the asynchronous validation operation. The task result contains the validation result with any errors found.

ValidateAsync(FullPath, CancellationToken)

NuGetPackageValidator.cs

Validates a NuGet package using the default set of validation rules.

public static Task<NuGetPackageValidationResult> ValidateAsync(FullPath packagePath, CancellationToken cancellationToken = default)
Parameters
packagePath FullPath
The path to the NuGet package file (.nupkg) to validate.
cancellationToken CancellationToken
A token to cancel the validation operation.
Returns

Task<NuGetPackageValidationResult> A task that represents the asynchronous validation operation. The task result contains the validation result with any errors found.