Top Tips and Shortcuts for Mastering NuGet Package Explorer
NuGet Package Explorer (NPE) is a lightweight GUI for creating, inspecting, and editing .nupkg files. Whether you’re packaging libraries, fixing metadata, or inspecting dependencies, these tips and keyboard shortcuts will speed up your workflow and help you avoid packaging mistakes.
1. Install the right build
- Windows Store app vs. desktop app: Prefer the desktop (Win32) version from the official GitHub releases for the most recent features and full file-system access. The Windows Store version can be convenient but may have sandbox limitations.
2. Use the quick keyboard shortcuts
- Ctrl+O — Open a package (.nupkg or .nuspec).
- Ctrl+S — Save changes to the current package.
- Ctrl+Shift+S — Save As (create a new .nupkg).
- Ctrl+N — Create a new package from scratch.
- Ctrl+F — Find text inside the package metadata.
- Delete — Remove the selected file or entry.
These reduce mouse travel and make edits faster.
3. Validate package metadata early
- Fill required metadata fields: id, version, authors, description, and licenseExpression or licenseUrl. Missing or malformed fields cause NuGet.org rejection or package quality issues.
- Use semantic versioning: follow MAJOR.MINOR.PATCH and include pre-release labels when appropriate (e.g., 1.2.3-beta.1).
4. Manage dependencies and frameworks correctly
- Target frameworks explicitly: add correct target framework folders (lib/net6.0, lib/netstandard2.0) rather than relying on broad compatibility assumptions.
- Group dependencies by target framework to avoid runtime binding surprises.
- Set appropriate dependency versions: prefer range expressions when you intend to allow compatible updates (e.g., [1.2.0,2.0.0) ), but be conservative for breaking changes.
5. Add and verify package assets correctly
- Include content and build assets under the appropriate folders (contentFiles, build, tools).
- Set correct LogicalName and target paths for files so consuming projects receive the intended assets.
- Verify package structure in the Explorer tree before saving — mismatched paths are a common source of bugs.
6. Use the Nuspec editor efficiently
- Edit XML directly for complex changes: the built-in XML view lets you make precise changes not exposed in the UI.
- Validate XML and encoding: ensure UTF-8 without BOM if you target cross-platform consumers.
7. Inspect and fix digital signing & hashing
- Check package signatures if you consume signed packages. NPE highlights signature info and lets you inspect the signer.
- Re-sign after modification: editing a package invalidates signatures; re-sign before publishing if signing is required.
8. Test local installation and unpacking
- Install the package locally into a sample project (use dotnet add package with a local source or NuGet CLI) to validate how it behaves when consumed.
- Unpack and run tests against the files that end up in the consuming project’s output.
9. Automate repetitive edits
- Script nuspec generation where possible (MSBuild props/targets, dotnet pack) and use NPE for inspection and last-mile tweaks.
- Use CI to build and validate packages: incorporate validation steps (nuget pack validation, dotnet restore/build/tests) to catch issues before publishing.
10. Keep publishing best practices in mind
- Use a proper license expression instead of embedding full license files unless required. Include a license file when using custom or complex licenses.
- Provide release notes and tags in your package metadata or on the release page to help consumers understand changes.
- Use consistent package IDs and ownership to prevent confusing duplicates on NuGet.org.
Bonus: Troubleshooting quick checks
- If a package fails to appear on NuGet.org: confirm id/version uniqueness and that required metadata is present.
- If consumers get runtime errors: check target framework folders, dependency ranges, and asset placement.
- If files are missing in the consuming project: verify contentFiles metadata, package path, and include/exclude settings.
Follow these tips to make NuGet Package Explorer a fast, reliable part of your packaging workflow.
Leave a Reply