A .NET library for validating NuGet packages to ensure they follow best practices and contain all required metadata and files.
This library provides a comprehensive set of validation rules to check NuGet packages (.nupkg) and symbol packages (.snupkg) for common issues, missing metadata, and compliance with NuGet best practices.
using Meziantou.Framework.NuGetPackageValidation;
// Validate a package with default rules
var result = await NuGetPackageValidator.ValidateAsync("MyPackage.1.0.0.nupkg");
if (result.IsValid)
{
Console.WriteLine("Package is valid!");
}
else
{
foreach (var error in result.Errors)
{
Console.WriteLine($"{error.ErrorCode}: {error.Message}");
if (error.HelpText != null)
{
Console.WriteLine($" Help: {error.HelpText}");
}
}
}// Validate with specific rules only
var result = await NuGetPackageValidator.ValidateAsync(
"MyPackage.1.0.0.nupkg",
new[]
{
NuGetPackageValidationRules.AuthorMustBeSet,
NuGetPackageValidationRules.LicenseMustBeSet,
NuGetPackageValidationRules.IconMustBeSet
});var options = new NuGetPackageValidationOptions();
// Add default rules
foreach (var rule in NuGetPackageValidationRules.Default)
{
options.Rules.Add(rule);
}
// Exclude specific error codes
options.ExcludedRuleIds.Add(ErrorCodes.IconNotSet);
// Configure symbol servers
options.SymbolServers.Clear();
options.SymbolServers.Add("https://msdl.microsoft.com/download/symbols/");
options.SymbolServers.Add("https://symbols.nuget.org/download/symbols/");
// Configure HTTP requests (e.g., add authentication)
options.ConfigureRequest = request =>
{
request.Headers.Add("X-Custom-Header", "value");
};
var result = await NuGetPackageValidator.ValidateAsync("MyPackage.1.0.0.nupkg", options);The following rules are included in NuGetPackageValidationRules.Default:
- AssembliesMustBeOptimized - Ensures assemblies are compiled in Release mode with optimizations enabled
- AuthorMustBeSet - Verifies the author metadata is set and not using default values
- DescriptionMustBeSet - Checks for a meaningful description (not default placeholder text)
- IconMustBeSet - Validates that a package icon is included (not deprecated iconUrl)
- LicenseMustBeSet - Ensures license information is provided (expression or file, not deprecated licenseUrl)
- ProjectUrlMustBeSet - Verifies a project URL is specified and accessible
- ReadmeMustBeSet - Checks that a readme file is included in the package
- RepositoryMustBeSet - Validates repository information is present
- Symbols - Comprehensive validation of debug symbols (PDB files), including:
- Symbol files are present (embedded, .pdb, or .snupkg)
- Deterministic builds are enabled
- Source Link is configured
- Portable PDB format is used (not full PDB)
- Compiler flags are present
- Source files are accessible or embedded
- TagsMustBeSet - Ensures package tags are defined and within length limits
- XmlDocumentationMustBePresent - Verifies XML documentation files are included for public APIs
These rules are available but not included by default:
- PackageIdAvailableOnNuGetOrg - Checks if the package ID is already taken on nuget.org (useful for new packages)
- RepositoryBranchMustBeSet - Validates that repository branch information is specified
Each validation error has a specific error code for easy identification and filtering:
1- FileNotFound: Package file not found2- InvalidPackage: Package file cannot be read as a NuGet package
11- AuthorNotSet: Author metadata is missing12- DefaultAuthorSet: Author is set to the default value (same as package ID)
21- LicenseNotSet: License information is missing22- UseDeprecatedLicenseUrl: Using deprecated licenseUrl instead of license expression/file23- LicenseFileNotFound: License file specified but not found in package
31- UseDeprecatedIconUrl: Using deprecated iconUrl instead of icon file32- IconNotSet: No icon specified33- IconNotFound: Icon file not found in package34- IconFileTooLarge: Icon file exceeds size limit35- IconFileFormatNotSupported: Icon file format is not PNG or JPEG36- IconFileInvalidExtension: Icon file extension doesn't match content
41- UseDeprecatedSummary: Using deprecated summary field42- DescriptionNotSet: Description is missing43- PackageHasDefaultDescription: Description is using default placeholder text44- PackageDescriptionIsTooLong: Description exceeds maximum length
51- ProjectUrlNotSet: Project URL is missing52- ProjectUrlNotAccessible: Project URL is not accessible
61- ReadmeNotSet: Readme file is not specified62- ReadmeFileNotFound: Readme file not found in package
71- RepositoryNotSet: Repository metadata is missing72- RepositoryTypeNotSet: Repository type not specified73- RepositoryUrlNotSet: Repository URL not specified74- RepositoryCommitNotSet: Repository commit hash not specified75- RepositoryBranchNotSet: Repository branch not specified
81- AssemblyIsNotOptimized: Assembly compiled in Debug mode or without optimizations
91- CannotCheckPackageIdExistsOnNuGetOrg: Unable to verify if package ID exists92- PackageIdExistsOnNuGetOrg: Package ID already exists on nuget.org
101- XmlDocumentationNotFound: XML documentation file not found
111- SymbolsNotFound: Debug symbols not found112- NonDeterministic: Build is not deterministic113- SourceFileNotAccessible: Source files not accessible114- CompilerFlagsNotPresent: Compiler flags not embedded in PDB115- InvalidCompilerVersion: Compiler version is invalid116- CompilerDoesNotSupportReproducibleBuilds: Compiler doesn't support reproducible builds117- FullPdb: Using full PDB format instead of portable PDB118- PdbDoesNotMatchAssembly: PDB file doesn't match assembly119- UrlIsNotAccessible: URL referenced in source link is not accessible120- FileHashIsNotValid: File hash validation failed121- FileHashIsNotProvided: File hash not provided122- NotSupportedHashAlgorithm: Hash algorithm not supported
131- TagsNotSet: Package tags are not set132- TagsTooLong: Tags exceed the 4000 character limit