$npx -y skills add Aaronontheweb/dotnet-skills --skill local-toolsManaging local .NET tools with dotnet-tools.json for consistent tooling across development environments and CI/CD pipelines.
| 1 | # .NET Local Tools |
| 2 | |
| 3 | ## When to Use This Skill |
| 4 | |
| 5 | Use this skill when: |
| 6 | - Setting up consistent tooling across a development team |
| 7 | - Ensuring CI/CD pipelines use the same tool versions as local development |
| 8 | - Managing project-specific CLI tools (docfx, incrementalist, dotnet-ef, etc.) |
| 9 | - Avoiding global tool version conflicts between projects |
| 10 | |
| 11 | ## What Are Local Tools? |
| 12 | |
| 13 | Local tools are .NET CLI tools that are installed and versioned per-repository rather than globally. They're defined in `.config/dotnet-tools.json` and restored with `dotnet tool restore`. |
| 14 | |
| 15 | ### Local vs Global Tools |
| 16 | |
| 17 | | Aspect | Global Tools | Local Tools | |
| 18 | |--------|--------------|-------------| |
| 19 | | Installation | `dotnet tool install -g` | `dotnet tool restore` | |
| 20 | | Scope | Machine-wide | Per-repository | |
| 21 | | Version control | Manual | In `.config/dotnet-tools.json` | |
| 22 | | CI/CD | Must install each tool | Single restore command | |
| 23 | | Conflicts | Can have version conflicts | Isolated per project | |
| 24 | |
| 25 | --- |
| 26 | |
| 27 | ## Setting Up Local Tools |
| 28 | |
| 29 | ### Initialize the Manifest |
| 30 | |
| 31 | ```bash |
| 32 | # Create .config/dotnet-tools.json |
| 33 | dotnet new tool-manifest |
| 34 | ``` |
| 35 | |
| 36 | This creates: |
| 37 | ``` |
| 38 | .config/ |
| 39 | └── dotnet-tools.json |
| 40 | ``` |
| 41 | |
| 42 | ### Install Tools Locally |
| 43 | |
| 44 | ```bash |
| 45 | # Install a tool locally |
| 46 | dotnet tool install docfx |
| 47 | |
| 48 | # Install specific version |
| 49 | dotnet tool install docfx --version 2.78.3 |
| 50 | |
| 51 | # Install from a specific source |
| 52 | dotnet tool install MyTool --add-source https://mycompany.pkgs.visualstudio.com/_packaging/feed/nuget/v3/index.json |
| 53 | ``` |
| 54 | |
| 55 | ### Restore Tools |
| 56 | |
| 57 | ```bash |
| 58 | # Restore all tools from manifest |
| 59 | dotnet tool restore |
| 60 | ``` |
| 61 | |
| 62 | --- |
| 63 | |
| 64 | ## dotnet-tools.json Format |
| 65 | |
| 66 | ```json |
| 67 | { |
| 68 | "version": 1, |
| 69 | "isRoot": true, |
| 70 | "tools": { |
| 71 | "docfx": { |
| 72 | "version": "2.78.3", |
| 73 | "commands": [ |
| 74 | "docfx" |
| 75 | ], |
| 76 | "rollForward": false |
| 77 | }, |
| 78 | "dotnet-ef": { |
| 79 | "version": "9.0.0", |
| 80 | "commands": [ |
| 81 | "dotnet-ef" |
| 82 | ], |
| 83 | "rollForward": false |
| 84 | }, |
| 85 | "incrementalist.cmd": { |
| 86 | "version": "1.2.0", |
| 87 | "commands": [ |
| 88 | "incrementalist" |
| 89 | ], |
| 90 | "rollForward": false |
| 91 | }, |
| 92 | "dotnet-reportgenerator-globaltool": { |
| 93 | "version": "5.4.1", |
| 94 | "commands": [ |
| 95 | "reportgenerator" |
| 96 | ], |
| 97 | "rollForward": false |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | ``` |
| 102 | |
| 103 | ### Fields |
| 104 | |
| 105 | | Field | Description | |
| 106 | |-------|-------------| |
| 107 | | `version` | Manifest schema version (always 1) | |
| 108 | | `isRoot` | Marks this as the root manifest (prevents searching parent directories) | |
| 109 | | `tools` | Dictionary of tool configurations | |
| 110 | | `tools.<name>.version` | Exact version to install | |
| 111 | | `tools.<name>.commands` | CLI commands the tool provides | |
| 112 | | `tools.<name>.rollForward` | Allow newer versions (usually false for reproducibility) | |
| 113 | |
| 114 | --- |
| 115 | |
| 116 | ## Common Tools |
| 117 | |
| 118 | ### Documentation |
| 119 | |
| 120 | ```bash |
| 121 | # DocFX - API documentation generator |
| 122 | dotnet tool install docfx |
| 123 | ``` |
| 124 | |
| 125 | ```json |
| 126 | "docfx": { |
| 127 | "version": "2.78.3", |
| 128 | "commands": ["docfx"], |
| 129 | "rollForward": false |
| 130 | } |
| 131 | ``` |
| 132 | |
| 133 | **Usage:** |
| 134 | ```bash |
| 135 | dotnet docfx docfx.json |
| 136 | dotnet docfx serve _site |
| 137 | ``` |
| 138 | |
| 139 | ### Entity Framework Core |
| 140 | |
| 141 | ```bash |
| 142 | # EF Core CLI for migrations |
| 143 | dotnet tool install dotnet-ef |
| 144 | ``` |
| 145 | |
| 146 | ```json |
| 147 | "dotnet-ef": { |
| 148 | "version": "9.0.0", |
| 149 | "commands": ["dotnet-ef"], |
| 150 | "rollForward": false |
| 151 | } |
| 152 | ``` |
| 153 | |
| 154 | **Usage:** |
| 155 | ```bash |
| 156 | dotnet ef migrations add InitialCreate |
| 157 | dotnet ef database update |
| 158 | ``` |
| 159 | |
| 160 | ### Code Coverage |
| 161 | |
| 162 | ```bash |
| 163 | # ReportGenerator for coverage reports |
| 164 | dotnet tool install dotnet-reportgenerator-globaltool |
| 165 | ``` |
| 166 | |
| 167 | ```json |
| 168 | "dotnet-reportgenerator-globaltool": { |
| 169 | "version": "5.4.1", |
| 170 | "commands": ["reportgenerator"], |
| 171 | "rollForward": false |
| 172 | } |
| 173 | ``` |
| 174 | |
| 175 | **Usage:** |
| 176 | ```bash |
| 177 | dotnet reportgenerator -reports:coverage.cobertura.xml -targetdir:coveragereport -reporttypes:Html |
| 178 | ``` |
| 179 | |
| 180 | ### Incremental Builds |
| 181 | |
| 182 | ```bash |
| 183 | # Incrementalist - build only changed projects |
| 184 | dotnet tool install incrementalist.cmd |
| 185 | ``` |
| 186 | |
| 187 | ```json |
| 188 | "incrementalist.cmd": { |
| 189 | "version": "1.2.0", |
| 190 | "commands": ["incrementalist"], |
| 191 | "rollForward": false |
| 192 | } |
| 193 | ``` |
| 194 | |
| 195 | **Usage:** |
| 196 | ```bash |
| 197 | # Get projects affected by changes since main branch |
| 198 | incrementalist --branch main |
| 199 | ``` |
| 200 | |
| 201 | ### Code Formatting |
| 202 | |
| 203 | ```bash |
| 204 | # CSharpier - opinionated C# formatter |
| 205 | dotnet tool install csharpier |
| 206 | ``` |
| 207 | |
| 208 | ```json |
| 209 | "csharpier": { |
| 210 | "version": "0.30.3", |
| 211 | "commands": ["dotnet-csharpier"], |
| 212 | "rollForward": false |
| 213 | } |
| 214 | ``` |
| 215 | |
| 216 | **Usage:** |
| 217 | ```bash |
| 218 | dotnet csharpier . |
| 219 | dotnet csharpier --check . # CI mode - fails if changes needed |
| 220 | ``` |
| 221 | |
| 222 | ### Code Analysis |
| 223 | |
| 224 | ```bash |
| 225 | # JB dotnet-inspect (requires license) |
| 226 | dotnet tool install jb |
| 227 | ``` |
| 228 | |
| 229 | ```json |
| 230 | "jb": { |
| 231 | "version": "2024.3.4", |
| 232 | "commands": ["jb"], |
| 233 | "rollForward": false |
| 234 | } |
| 235 | ``` |
| 236 | |
| 237 | --- |
| 238 | |
| 239 | ## CI/CD Integration |
| 240 | |
| 241 | ### GitHub Actions |
| 242 | |
| 243 | ```yaml |
| 244 | jobs: |
| 245 | build: |
| 246 | runs-on: ubuntu-latest |
| 247 | steps: |
| 248 | - uses: actions/checkout@v4 |
| 249 | |
| 250 | - name: Setup .NET |
| 251 | uses: actions/setup-dotnet@v4 |
| 252 | with: |
| 253 | global-json-file: global.json |
| 254 | |
| 255 | - name: Restore tools |
| 256 | run: dotnet tool restore |
| 257 | |
| 258 | - name: Build |