Skip to main content
rule CX Codex

dependency-management — rule for Claude Code and Cursor

Rule for secure NuGet dependency management: vulnerability scanning, license compliance, versioning via dotnet CLI. Auto-applies to project files.

Apache-2.0 ★ 138 updated 2025-03-29

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/dependency-management.mdc
Open on GitHub

What dependency-management does

This rule guides an AI coder to use dotnet CLI commands instead of editing .csproj and .fsproj directly, verify licenses before adding packages, and monitor vulnerabilities with dotnet list package --vulnerable. It covers project files: Directory.Packages.props, *.csproj, *.fsproj, and nuget.config.

Includes command examples: add a package with a specific version (dotnet add package Serilog -v 3.1.1), list outdated packages (dotnet list package --outdated), generate lock files, and run security scans. The rule assumes central version management through Directory.Packages.props with semantic versioning: lock major versions for stability, allow minor updates for features, auto-update patches for security.

Enforces license verification before installation and CI/CD checks for vulnerabilities and license compliance. Recommends checking release notes for breaking changes, running tests after updates, and maintaining a clean dependency tree.

What it helps with

  • choose between dotnet CLI and manual config editing
  • find outdated and vulnerable packages in your solution
  • add a package while checking license compatibility
  • update a package and verify code compatibility
  • set up version constraints for major, minor, and patch releases

Example prompts for the agent

  • Add Serilog version 3.1.1 to the main project
  • Show all outdated packages and their available versions
  • List any packages with known security vulnerabilities

How to install dependency-management

Manually: put the files in place

.cursor/rules/dependency-management.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about dependency-management

How do I install the dependency-management rule in Claude Code?

Create .claude/rules/dependency-management.md in your project root and paste the rule content. Claude Code will load it on the next session.

What does this rule do?

It directs the AI coder to use dotnet CLI for package operations instead of direct file editing, verify licenses before install, and scan for vulnerabilities using dotnet list package --vulnerable. It also recommends centralized versioning via Directory.Packages.props.

How do I check for vulnerable packages?

Run dotnet list package --vulnerable. For full analysis, first generate a lock file with dotnet restore --use-lock-file.

Source text

dependency-management.mdc · Apache-2.0
---
description: This file provides guidelines for safely managing NuGet package dependencies in .NET projects, focusing on security, licensing, and maintainability.
globs: Directory.Packages.props,*.csproj,*.fsproj,Directory.Build.props,nuget.config
alwaysApply: false
---

# Cursor Rules File: Best Practices for .NET Dependency Management
Role Definition:
 - Package Management Expert
 - Security Analyst
 - License Compliance Specialist

General:
  Description: >
    .NET projects must manage their dependencies using secure and consistent practices,
    with attention to security vulnerabilities, license compliance, and proper version
    management through the dotnet CLI.
  Requirements:
    - Use dotnet CLI for package management
    - Verify package licenses before installation
    - Monitor for security vulnerabilities
    - Maintain consistent versioning strategies

Package Installation:
  - Always use dotnet CLI commands:
      - Preferred: `dotnet add package <PackageId> [-v <Version>]`
      - Avoid manual .csproj/.fsproj edits
      - Examples:
        ```bash
        # Add latest stable version
        dotnet add package Newtonsoft.Json
        
        # Add specific version
        dotnet add package Serilog -v 3.1.1
        
        # Add package to specific project
        dotnet add MyProject/MyProject.csproj package Microsoft.Extensions.Logging
        ```
  - Before installation:
      - Check package license compatibility
      - Review package download statistics
      - Verify package authenticity (signed packages)
      - Consider package maintenance status

Check and Upgrade NuGet Packages:

  To check for outdated packages and upgrade them in your .NET solution:

  1. **Check for outdated packages**
     ```bash
     dotnet list package --outdated
     ```
     This command will show:
     - Currently used version ("Resolved")
     - Latest available version ("Latest")
     - The version you're requesting ("Requested")

  2. **Update package versions**
     - If using central package management (Directory.Packages.props):
       - Update the versions in `Directory.Packages.props`:
       ```xml
       <PackageVersion Include="PackageName" Version="NewVersion" />
       ```

     - If using traditional package references:
       ```bash
       dotnet add package PackageName --version NewVersion
       ```

  3. **Restore and verify**
     ```bash
     dotnet restore
     dotnet build
     dotnet test
     ```

  Example output of `dotnet list package --outdated`:
  ```
  Project `MyProject` has the following updates to its packages
     [netstandard2.1]:
     Top-level Package      Requested   Resolved   Latest
     > Akka.Streams         1.5.13      1.4.45     1.5.38
  ```

  Note: After updating packages, always:
  1. Check for breaking changes in the package's release notes
  2. Build the solution to catch any compatibility issues
  3. Run tests to ensure everything still works
  4. Review and update any code that needs to be modified for the new versions

Security Considerations:
  - Enable security scanning:
      - Run `dotnet restore --use-lock-file` to generate lock file
      - Use `dotnet list package --vulnerable` to check for known vulnerabilities
      - Configure GitHub Dependabot or similar tools
  - Monitor security:
      - Subscribe to security advisories
      - Regular vulnerability scanning in CI/CD
      - Automated security updates for patch versions
  - Example workflow:
    ```bash
    # Generate lock file
    dotnet restore --use-lock-file
    
    # Check for vulnerabilities
    dotnet list package --vulnerable
    
    # Update vulnerable package
    dotnet add package VulnerablePackage -v SecureVersion
    
    # Regenerate lock file
    dotnet restore --force-evaluate
    ```

License Compliance:
  - Verify licenses before adding dependencies:
      - Check license compatibility with your project
      - Document license requirements
      - Maintain license inventory
  - Common OSS-friendly licenses:
      - MIT
      - Apache 2.0
      - BSD
      - MS-PL
  - Warning signs:
      - No license specified
      - Restrictive licenses (GPL for commercial software)
      - License changes between versions

Version Management:
  - Use semantic versioning:
      - Lock major versions for stability
      - Allow minor updates for features
      - Auto-update patches for security
  - Version constraints:
      - Avoid floating versions (*)
      - Use minimum version constraints when needed
      - Document version decisions
  - Example in Directory.Packages.props:
    ```xml
    <Project>
      <ItemGroup>
        <!-- Locked major version -->
        <PackageVersion Include="Important.Package" Version="2.0.0" />
        
        <!-- Allow minor updates -->
        <PackageVersion Include="Feature.Package" Version="[3.0,4.0)" />
        
        <!-- Allow patch updates -->
        <PackageVersion Include="Stable.Package" Version="[1.2.3,1.3.0)" />
      </ItemGroup>
    </Project>
    ```

Maintenance:
  - Regular housekeeping:
      - Remove unused packages
      - Consolidate duplicate dependencies
      - Update documentation
  - Automation:
      - Implement automated vulnerability scanning
      - Set up dependency update workflows
      - Configure license compliance checks
  - Commands for maintenance:
    ```bash
    # List all packages
    dotnet list package
    
    # Check for unused dependencies
    dotnet remove package UnusedPackage
    
    # Clean solution
    dotnet clean
    dotnet restore --force
    ```

Integration with CI/CD:
  - Implement checks:
      - Vulnerability scanning
      - License compliance
      - Package restore verification
  - Example GitHub Actions workflow:
    ```yaml
    - name: Security scan
      run: |
        dotnet restore --use-lock-file
        dotnet list package --vulnerable
        
    - name: License check
      run: dotnet-project-licenses
    ```

# End of Cursor Rules File 

© Aaronontheweb · Apache-2.0 · Aaronontheweb/dotnet-cursor-rules

Similar IDE rules

All IDE rules for Backend and APIs →

From the same set11

The whole set →
meta The meta rule guides edits to *.mdc files, preserving their formatting and steering agents toward existing rule files before creating new ones. CX Codex +1 ★ 138repo stars publishing-dotnettool Guides AI agents when creating and publishing dotnet tools to NuGet. Ensures semantic versioning, correct packaging, and compatibility across .NET versions. CX Codex +1 ★ 138repo stars code-signing Enforces .NET code signing patterns and SignClient configuration for NuGet packages in CI/CD pipelines. CX Codex +1 ★ 138repo stars consuming-dotnettool The consuming-dotnettool rule keeps .NET tool dependencies in a manifest, pins their versions, and adds restore steps for CI/CD. Use it when projects need repeatable tool setup. CX Codex +1 ★ 138repo stars solution-management solution-management standardizes .NET solution architecture with explicit SDK pinning, shared build properties, and centralized package management. CX Codex +1 ★ 138repo stars benchmarking The benchmarking rule teaches the agent to write valid .NET performance tests using BenchmarkDotNet. Useful when you need to measure code speed and track regressions. CX Codex +1 ★ 138repo stars nuget-package-publishing nuget-package-publishing — a rule that teaches the agent to pack .NET libraries into NuGet packages following industry standards: SPDX license, README, and debug symbols. CX Codex +1 ★ 138repo stars testing Defines xUnit testing conventions for .NET: project configurations, test isolation, coverage thresholds, and integration test setup. CX Codex +1 ★ 138repo stars

Project sponsors

Companies that keep this analytics open