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 NuGetPackageValidatorExample
// 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
| Name | Description |
|---|---|
| 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.csValidates 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
packagePathFullPath- The path to the NuGet package file (.nupkg) to validate.
optionsNuGetPackageValidationOptions- The validation options that specify which rules to apply and other configuration settings.
cancellationTokenCancellationToken- 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.csValidates a NuGet package using a custom set of validation rules.
public static Task<NuGetPackageValidationResult> ValidateAsync(FullPath packagePath, IEnumerable<NuGetPackageValidationRule> rules, CancellationToken cancellationToken = default)Parameters
packagePathFullPath- The path to the NuGet package file (.nupkg) to validate.
rulesIEnumerable<NuGetPackageValidationRule>- The collection of validation rules to apply.
cancellationTokenCancellationToken- 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.csValidates a NuGet package using the default set of validation rules.
public static Task<NuGetPackageValidationResult> ValidateAsync(FullPath packagePath, CancellationToken cancellationToken = default)Parameters
packagePathFullPath- The path to the NuGet package file (.nupkg) to validate.
cancellationTokenCancellationToken- 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.