nuget
Manages NuGet dependencies and packages in .NET repos. Use for Directory.Packages.props and Central Package Management, bumping or aligning package versions, NU1xxx restore warnings, nuget.config sources and source mapping, vulnerable-package audits, lock files, dotnet pack metadata, publishing to nuget.org with trusted publishing, or authoring, validating and packing `dotnet new` templates (template.json, a template missing from `dotnet new list`).
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- nuget
- license
- MIT
- description
- Manages NuGet dependencies and packages in .NET repos. Use for Directory.Packages.props and Central Package Management, bumping or aligning package versions, NU1xxx restore warnings, nuget.config sources and source mapping, vulnerable-package audits, lock files, dotnet pack metadata, publishing to nuget.org with trusted publishing, or authoring, validating and packing `dotnet new` templates (template.json, a template missing from `dotnet new list`).
02 资源文件 6
- 参考文档references/cpm.md7.8 KB
- 参考文档references/sources-and-audit.md5.1 KB
- 参考文档references/template-json.md5.7 KB
- 参考文档references/template-validation-rules.md4.5 KB
- 参考文档references/templates.md9.1 KB
- 参考文档references/trusted-publishing.md6.7 KB
03 SKILL.md 正文
NuGet
Change package versions and package configuration without changing anything else about the build, and prove it with a before/after restore.
Not for: MSBuild failures that aren't about packages (msbuild), C# code changes after an API break (csharp), vetting whether a new third-party package is trustworthy (dependency-vetting), CI workflow hardening beyond the publish job (gh-actions), packages.config to PackageReference migration (dotnet-upgrade-guide), using an existing dotnet new template to scaffold a project.
Pick the mode first
Decide before running builds or editing files.
- Guard. Any in-scope project uses
packages.config: stop. CPM, source mapping perPackageReference, lock files andNuGetAuditwarnings all needPackageReference; recommend migrating first and change nothing. - Package maintenance. "Update", "bump", "align", "sync", "fix NU1605": edit the versions where they already live (project file,
Directory.Build.propsproperty, orDirectory.Packages.propsif CPM is on), then restore and build every affected target. Don't introduce CPM as a side effect; recommend it afterwards if versions drift across projects. - CPM conversion. Only when the user asks to adopt, enable or convert to Central Package Management. Follow references/cpm.md.
- Sources, audit and lock files.
nuget.config,packageSourceMapping,NuGetAudit*, NU1900-NU1904,packages.lock.json: references/sources-and-audit.md. - Packing and publishing.
dotnet packmetadata, tool/MCP-server packages, pushing to nuget.org from GitHub Actions: references/trusted-publishing.md. dotnet newtemplates. Turning a project into a template,template.jsonsymbols, conditions, post-actions and constraints, a template pack (PackageTypeTemplate), validating a template.json before publishing, a template that installs but is missing fromdotnet new list: references/templates.md, which links references/template-json.md and references/template-validation-rules.md. Template work skips thepackages.configguard and the resolved-package comparison below; prove it by instantiating and building the template instead.
Ask once if the scope (which projects or solution) is unclear. If the user gave a conflict strategy ("use the highest version"), apply it without asking again.
Orient
- Find where each version is declared:
grep -rn --include='*.csproj' --include='*.props' --include='*.targets' -E 'PackageReference|PackageVersion|GlobalPackageReference|VersionOverride' .and any$(XxxVersion)properties those reference. Check ancestors forDirectory.Packages.props(only the nearest one applies to a project). - Read
nuget.configfiles from the repo root upward, andglobal.json. Run everydotnetcommand from the directory whoseglobal.jsonapplies to that solution. - See what actually resolved, not just what is declared. SDK 10 and later:
dotnet package list --project <sln|proj> --include-transitive --format json. SDK 7.0.200 to 9.x:dotnet list <sln|proj> package --include-transitive --format json. Add--outdated,--vulnerableor--deprecatedonly when that question is asked. - For a package's API change between versions, read its release notes, or query Context7 (
resolve-library-id, thenquery-docs) for the target version.
Version rules
- Change only the packages requested. Don't upgrade past the highest version already used in scope during an alignment or conversion; list newer versions and advisories as follow-ups.
- Treat a major-version change as high risk (API breaks): build every consumer and run its tests. Minor and patch changes are moderate; build all consumers.
- Keep every non-version attribute and condition on a
PackageReference(PrivateAssets,IncludeAssets,ExcludeAssets,GeneratePathProperty,Aliases, TFM conditions). - Packages that ship together move together:
Microsoft.Extensions.*,Microsoft.AspNetCore.*,Microsoft.EntityFrameworkCore.*of one release train,xunit.*,OpenTelemetry.*. A mismatch shows up as NU1605 (downgrade) or NU1608 (outside a dependency's range). - NU1605 means a direct reference pins a lower version than a transitive dependency needs: raise the direct reference; don't suppress the warning.
- Analyzer and build-only packages get
PrivateAssets="all"so they don't flow to consumers.
Validate
- Capture resolved packages before the change (the list command above, redirected to a file).
- Make the edit.
dotnet restore <target>thendotnet build <target> --no-restorefor every affected solution or project. New NU1xxx warnings count as failures to explain.- Capture the resolved list again and compare per project: version changes, packages added or removed. Every difference must be one you intended.
- If resolved versions changed, run the affected projects' tests (
dotnet test <proj> --no-build), or give the exact command if they need infrastructure.
Don't install or switch SDKs, edit global.json roll-forward, clear the global packages folder (dotnet nuget locals all --clear) or change machine-level NuGet config as a fix; report the blocker instead.
Gotchas
| Code | Meaning | Fix |
|---|---|---|
| NU1008 | CPM on, but a PackageReference still has Version |
Remove it, or use VersionOverride deliberately |
| NU1010 | CPM on, PackageReference has no PackageVersion |
Add the PackageVersion |
| NU1101 / NU1102 | Package or version not found on any source | Check source mapping and feed auth before the ID |
| NU1507 | Several sources, no packageSourceMapping |
Add mapping (sources-and-audit) |
| NU1603 | Requested version absent, a higher one resolved | Pin an existing version |
| NU1901-NU1904 | Known vulnerability (low to critical) | Upgrade the package or the transitive one; suppress only with a recorded reason |
- After
dotnet add package(ordotnet package add) in a CPM repo, check the diff: thePackageVersionbelongs inDirectory.Packages.props, not aVersionon the reference. - A
Directory.Packages.propsin a subfolder replaces the parent one for projects under it; it does not merge unless it imports the parent. - Floating versions (
1.*) make restores non-reproducible; with a lock file they need--force-evaluateto move.
04 同仓库更多 Skills
msbuild
Diagnoses MSBuild failures and slow builds and reviews .NET build XML. Use for a failing dotnet build, restore, pack or publish, .csproj/.props/.targets conditions and custom targets, binlog capture and replay, "it rebuilds when nothing changed", slow evaluation or builds, bin/obj clashes, or Directory.Build.* layering.
csharp
Writes, reviews, refactors and debugs C# and .NET code (types, nullable references, async and cancellation, exceptions, DI, options and logging in the generic host, file-based apps). Use for work in *.cs or *.csx files, "review this C# class", CS86xx nullable warnings, CA or IDE warnings and .editorconfig severity, a deadlock or sync-over-async bug, or a rename across a solution. Not for Godot C# (godot-csharp).