·
Last changedVersion:
No hardening report available.
This skill ensures consistent and safe management of NuGet packages across .NET projects. It prioritizes using the dotnet CLI to maintain project integrity and enforces a strict verification and restoration workflow for version updates.
WARNING: Command Injection and XML Injection Risk
This skill constructs shell commands and edits XML project files using package names and versions supplied by the user. To prevent command injection and MSBuild/XML injection, you MUST validate any user-provided value for <PACKAGE_NAME>, <VERSION>, and <PROJECT> before using it in a command or writing it to a file.
^[A-Za-z0-9._\-]+$.This validation blocks shell metacharacters and XML-significant characters (such as " and >), mitigating both command injection in shell pipelines and MSBuild injection when editing .csproj or Directory.Packages.props files.
dotnet CLI available on your PATH.jq (JSON processor) for version verification using dotnet package search..csproj, .props, or Directory.Packages.props files to add or remove packages. Always use dotnet add package and dotnet remove package commands..csproj) or centrally (Directory.Packages.props).dotnet restore to verify compatibility.^[A-Za-z0-9._\-]+$. Reject and abort if the value contains characters outside this set. This applies to <PACKAGE_NAME>, <VERSION>, and <PROJECT> placeholders in all commands below.Use dotnet add [<PROJECT>] package <PACKAGE_NAME> [--version <VERSION>].
Example: dotnet add src/MyProject/MyProject.csproj package Newtonsoft.Json
Use dotnet remove [<PROJECT>] package <PACKAGE_NAME>.
Example: dotnet remove src/MyProject/MyProject.csproj package Newtonsoft.Json
When updating a version, follow these steps:
Verify Version Existence:
Check if the version exists using the dotnet package search command with exact match and JSON formatting.
Using jq:
dotnet package search <PACKAGE_NAME> --exact-match --format json | jq -e '.searchResult[].packages[] | select(.version == "<VERSION>")'
Determine Version Management:
Directory.Packages.props in the solution root. If present, versions should be managed there via <PackageVersion Include="Package.Name" Version="1.2.3" />..csproj files for <PackageReference Include="Package.Name" Version="1.2.3" />.Apply Changes:
After validating the new version string against ^[A-Za-z0-9._\-]+$ (per Core Rule 4), modify the identified file with the new version string. Do not construct XML attribute values from unvalidated input; the version string must be a plain Major.Minor.Patch[-prerelease] token with no embedded XML characters.
Verify Stability:
Run dotnet restore on the project or solution. If errors occur, revert the change and investigate.
Action: Execute dotnet add src/WebApi/WebApi.csproj package Serilog.
Action:
dotnet package search Newtonsoft.Json --exact-match --format json | jq -e '.searchResult[].packages[] | select(.version == "13.0.3")' (confirm "13.0.3" is present in output).Directory.Packages.props).13.0.3 matches ^[A-Za-z0-9._\-]+$).dotnet restore.Need this version hardened?
Bring Chainguard's hardening pipeline to your first-party skills — custom rulesets, automated remediation, full audit trail.
—
—
MIT
HARDENING.md
LICENSE
SKILL.md