Centralizes and manages NuGet package dependencies and versions within the repository.
Install
mkdir -p .claude/skills/nuget && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/17819" && unzip -o skill.zip -d .claude/skills/nuget && rm skill.zipInstalls to .claude/skills/nuget
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Upgrade, add, remove, or review NuGet package references and dependencies in this repo. Use when changing `version.json`, `Directory.Packages.props`, `<PackageReference/>` elements in `*.csproj` files, or diagnosing dependency conflicts.Key capabilities
- →Upgrade NuGet package references.
- →Add new NuGet package references.
- →Remove NuGet package references.
- →Review NuGet package dependencies.
- →Diagnose dependency conflicts using Central Package Management.
How it works
This skill provides guidelines for managing NuGet packages using Central Package Management, ensuring consistent versions and helping diagnose conflicts. It outlines how to organize dependencies and use diagnostic tools.
Inputs & outputs
When to use nuget
- →Adding a NuGet package
- →Resolving dependency conflicts
- →Updating project dependencies
About this skill
NuGet Package Guidelines
Definition of terms:
- Library is a project in this repo. Most libraries build NuGet packages.
- Test is a project in this repo. Most test projects test a single library.
- Dependency is a NuGet package consumed by this repo.
- TFM is a
TargetFrameworkmoniker likenet8.0,net462, etc.
Organization
- Use Central Package Management. All libraries must be tested with the same dependencies so that they can all be loaded by the same consumer.
- Set
CentralPackageTransitivePinningEnabledtotrue. Transitive dependencies pinned in theDirectory.Packages.propsdon't have to be referenced in every project separately. - Make
Directory.Build.propsplace all build outputs in the root of the repository to detect transitive dependency conflicts as double-writes in the MSBuild structured .binlog and allow this skill to find project assets.<BaseOutputPath>$(MSBuildThisFileDirectory)bin\</BaseOutputPath> <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> - Split the library and test dependencies in separate
Directory.Packages.props. Prevent accidental leakage of test-only dependencies into the libraries through the central pinning.- Place dependencies shared by both libraries and tests in the repo root.
- Place library-only dependencies like
Nerdbank.GitVersioningin thesrcfolder. - Place test-only dependencies like
xunit.v3in thetestfolder. - Make the library- and test-specific files
<Import Project="..\Directory.Packages.props" />with shared dependencies.
- Keep
<PackageVersion/>and<PackageReference/>items sorted. Avoid discrepancies introduced in parallel and reduce merge conflicts. - Add end-of-line comments for non-trivial packages and versions.
Comments are end-of-line to simplify sorting.
- Keep lines short:
- Use acronyms for package names:
x.v.ainstead ofxunit.v3.assert. Most package names already appear in the.propsfile or can be easily determined byGet-Packages. - Combine packages with the same dependency version:
(M, M.B.AI)->4.5.4instead ofM->4.5.4; M.B.AI->4.5.4. - Use wildcards for package families:
M.*->4.5.4instead of(M.B.AI, M.E.DI)->4.5.4.
- Use acronyms for package names:
- Explain versions held below latest to maintain transitive SemVer contract or minimize the dependency graph.
<PackageVersion Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.12" /> <!-- 3.2.2 breaks SemVer: S.C.I 8.0.0->9.0.8 --> - Explain transitive pins.
- Required to resolve conflicts.
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" /> <!-- x.v.a->6.0.0; M.D.T.TE->8.0.0 --> - Required to avoid vulnerabilities.
<PackageVersion Include="System.Text.Json" Version="8.0.5" /> <!-- M.E.L.C->8.0.4 vulnerable: CVE-2024-43485 -->
- Required to resolve conflicts.
- Keep lines short:
- Add explicit
$(TargetFramework)conditions to every target-specific dependency. Make the target-specific intent explicit, easier to understand and help detect discrepancies as build errors.- Make both
<PackageVersion/>and<PackageReference/>items conditional. - Add
Condition="'$(TargetFramework)' == '{TFM}'"for packages used by a single target. - Add
Condition="$(TargetFramework.StartsWith('net4'))"for packages used by multiple .NET Framework targets, such as when anet462library is tested by anet472test. - Place
Conditionattribute afterIncludeto allow re-sorting the package items quickly. E.g. <PackageReference Include="Microsoft.Bcl.Memory" Condition="'$(TargetFramework)' == '{TFM}'"/> - When multiple items need the same condition, move them to an
<ItemGroup Condition="..."/>. - Don't create single-item <ItemGroup Condition="..."/>, add
Condition="..."to the package items instead
- Make both
Diagnostics
-
Use NuGet MCP tools to plan version changes. If unavailable, use
dotnet list package --vulnerableanddotnet list package --outdated. -
Run
dotnet nuget whyto understand dependency chains and target frameworks. Note that it prints the dependency versions resolved for projects and not the versions requested by the packages.dotnet nuget why 'System.Collections.Immutable' # All projects, all frameworks dotnet nuget why test/Actors 'System.Collections.Immutable' # Limit to project dotnet nuget why test/Actors 'System.Collections.Immutable' -f net472 # Limit to framework -
Use
Get-Packagesfrom.github/skills/nuget/scripts/NuGetHelpers.ps1to understand requested versions. It usesobj/{ProjectName}/project.assets.jsonfiles to emit one row per parent -> dependency edge with both the constraint string (RequestedVersion) and the version NuGet picked (ResolvedVersion).dotnet restore # Generates project.assets.json files . ./.github/skills/nuget/scripts/NuGetHelpers.ps1 Get-Packages | Where-Object Package -eq 'System.Collections.Immutable' # Limit to package Get-Packages | Where-Object Framework -eq 'net472' # Limit to framework Get-Packages | Where-Object Project -eq 'Microsoft.ServiceFabric.Actors.Tests' # Limit to project Get-Packages | Format-Table -AutoSize # For human analysis -
Use
Get-PackageConflictsfrom.github/skills/nuget/scripts/NuGetHelpers.ps1to find dependency conflicts.Get-PackageConflicts | Select-Object Package, RequestedVersion, Framework -Unique # All conflictsAlternatively, open
msbuild.binlog(produced bydotnet build -bl) in the MSBuild Structured Log Viewer and inspect the synthesizedDoubleWritesnode; it lists.dllfile paths with conflicting package versions.
Rules
- Check for upgrades whenever the library
version.jsonchanges. Every release should use latest (highest-quality, most secure and performant) dependencies subject to the rules below. - Choose direct dependency versions with least transitive conflicts
E.g. with existing dependency
D1->T/1.0.0addingD2/2.0.0->T/2.0.0introduces conflict betweenT/1.0.0andT/2.0.0and requires a transitive pin. IfD2/1.0.0->T/1.0.0the olderD2version should be referenced instead.- For each direct dependency that introduces transitive conflict, check its older versions, including older major versions and find the latest not-vulnerable and not-deprecated version that doesn't.
- Prefer downgrading direct dependencies to avoid transitive conflicts over resolving them with pinning.
- Minimize the combined dependency graph for consumers.
Libraries cannot be tested with every possible combination of current and future dependencies that may be used by consumers.
Minimizing the dependency graph is particularly important for .NET Framework libraries, where failures caused by version
mismatch of strongly-named assemblies are more common than the actual breaking changes.
- For dependencies aligned with .NET, build library with matching
TargetFrameworksand target-specific dependency versions. Example:Microsoft.Extensions.*package family shipped versions8.*with .NET 8 and10.*with .NET 10. Library referencing them with thenet8.0TFM should also have thenet10.0TFM and reference target-specific versions.
- For dependencies aligned with .NET, build library with matching
- Upgrade direct dependencies to their latest stable versions within SemVer constraints.
Libraries should maintain the SemVer contract transitively. Some packages break the SemVer contract. For example,
Microsoft.Diagnostics.Tracing.TraceEvent -> System.Collections.Immutablereference3.1.12 -> 8.0.0jumped to3.2.2 -> 9.0.8.- Upgrade to latest minor, SemVer-compatible dependency versions before shipping every minor new version of the libraries.
- Upgrade to latest major dependency versions before shipping every major new version of the libraries.
- Upgrade vulnerable and deprecated dependencies to the recommended version.
Vulnerable and deprecated dependencies may be reported as build errors and must be upgraded irrespective of the library
release cycle.
- Do maintain the SemVer contract while upgrading vulnerable dependencies. Most vulnerabilities are addressed by patch versions, which can be referenced at any time.
- If upgrading library dependencies is not possible under SemVer rules, pin the recommended dependency version for tests.
Suppose a library with dependency on
Foovulnerable version1.0.0with recommended upgrade to version2.0.0. If a new major version of the library cannot be released immediately,Fooshould be pinned to version2.0.0for tests only, while the library will continue shipping with dependency on1.0.0.
- Resolve transitive dependency conflicts
- Choose direct dependency versions with least transitive conflicts as described above.
- Pin remaining conflicting transitive dependencies to the higher of the conflicting versions, which may not be the latest.
- Don't upgrade transitive pins unless they are vulnerable.
- Remove unnecessary <PackageVersion/> and <PackageReference/> items.
- Projects should have the minimum number of
<PackageReference/>items required to build. Directory.Packages.propsfiles should have the minimum number of<PackageVersion/>items required to meet these rules.
- Projects should have the minimum number of
- Revalidate the combined dependency graph after adding, removing or changing any <PackageVersion/> or <PackageReference/>.
Use
Get-PackageConflictsfrom.github/skills/nuget/scripts/NuGetHelpers.ps1to find dependency conflicts as described above. Any new package or version in any project can change the combined dependency graph for the repo and break these rules.
When not to use it
- →When not dealing with NuGet package references or dependencies.
- →When the project does not use Central Package Management.
Limitations
- →All libraries must be tested with the same dependencies.
- →Transitive dependencies pinned in `Directory.Packages.props` don't have to be referenced in every project separately.
- →Requires `CentralPackageTransitivePinningEnabled` to be `true`.
How it compares
This skill enforces specific organizational patterns and diagnostic workflows for NuGet packages within a Central Package Management setup, unlike general NuGet usage which might not follow these conventions.
Compared to similar skills
nuget side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| nuget (this skill) | 0 | 1mo | Review | Intermediate |
| dependency-update | 1 | 2mo | Review | Intermediate |
| update-roslyn-version | 2 | 2mo | Review | Advanced |
| csharp-developer | 43 | 2mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by microsoft
View all by microsoft →You might also like
dependency-update
dotnet
Guides dependency version updates by checking nuget.org for latest versions, triggering the dotnet-migrate-package Azure DevOps pipeline, and monitoring runs. Use this when asked to update external NuGet dependencies.
update-roslyn-version
dotnet
Guide for updating the Roslyn language server version in the vscode-csharp repository. Use this when asked to update Roslyn, bump the Roslyn version, or upgrade the language server version.
csharp-developer
zenobi-us
Expert C# developer specializing in modern .NET development, ASP.NET Core, and cloud-native applications. Masters C# 12 features, Blazor, and cross-platform development with emphasis on performance and clean architecture.
github-actions-templates
wshobson
Create production-ready GitHub Actions workflows for automated testing, building, and deploying applications. Use when setting up CI/CD with GitHub Actions, automating development workflows, or creating reusable workflow templates.
csharp-pro
sickn33
Write modern C# code with advanced features like records, pattern matching, and async/await. Optimizes .NET applications, implements enterprise patterns, and ensures comprehensive testing. Use PROACTIVELY for C# refactoring, performance optimization, or complex .NET solutions.
dotnet-architect
sickn33
Expert .NET backend architect specializing in C#, ASP.NET Core, Entity Framework, Dapper, and enterprise application patterns. Masters async/await, dependency injection, caching strategies, and performance optimization. Use PROACTIVELY for .NET API development, code review, or architecture decisions.