With the .NET 10 SDK, how do global tools, tool-path tools and local tools differ in where they install and how you invoke them?
answer
- a NuGet package holding a console app
- -g: per user, ~/.dotnet/tools on PATH
- --tool-path: your folder, not on PATH
- local: listed in a manifest per repository
- dotnet tool run X or dotnet X
basics
~20 sA .NET tool is a console app shipped as a NuGet package; -g installs it per user into ~/.dotnet/tools on PATH, --tool-path into a folder you choose, and a local install records it in a repository's tool manifest, invoked through dotnet.
solid answer
~40 sA **.NET tool** is a NuGet package of type `DotnetTool` that contains a console app. `dotnet tool install -g <id>` installs it for the current user under `$HOME/.dotnet/tools` (`%USERPROFILE%\.dotnet\tools` on Windows), which the SDK adds to PATH, so you type the command anywhere; one version serves the whole machine for that user. `--tool-path <dir>` installs into a folder you choose and does not touch PATH, which suits build agents and containers. A **local tool** is installed without `-g` or `--tool-path`: the SDK records its id, version and command in a `dotnet-tools.json` manifest, and you run it with `dotnet tool run <command>` or `dotnet <command>` from that directory tree, so each repository pins its own version. Tools run in full trust, so only install ones you trust.
code
bash · 11 lines# Global: per user, on PATH
dotnet tool install -g dotnet-ef
dotnet-ef --version
# Tool-path: a folder you control, not on PATH
dotnet tool install dotnet-ef --tool-path ./.tools
./.tools/dotnet-ef --version
# Local: recorded in the repository's manifest
dotnet tool install dotnet-ef
dotnet tool run dotnet-ef --version # or: dotnet ef --versiongo deeper
Recall that a .NET tool is a console app in a NuGet package, that -g installs it for your user on PATH, and that local tools are run through dotnet.
Explain the three install modes, where each lands, the dotnet- prefix shortcut, and why a local tool wins over a global one inside its repository.
Choose per situation: manifests for anything a build or teammate depends on, tool-path for scripted agents, global only for personal conveniences, and treat every tool as trusted code.
Set a policy for developer tooling: which tools a repository pins, which feeds they may come from, and how the team reviews a new tool before it enters the manifest.
## What a .NET tool is A **.NET tool** is an ordinary .NET console application packed into a NuGet package whose package type is `DotnetTool`. The `dotnet tool` commands download it from your configured NuGet feeds and make its command available. Well-known examples are `dotnet-ef` (the EF Core command-line tool) and the diagnostics tools. Because a tool is code you download and execute, it runs **in full trust**: install only tools whose author you trust. ## Three ways to install | Mode | Command | Where it lands | How you run it | Version scope | |---|---|---|---|---| | Global | `dotnet tool install -g dotnet-ef` | `$HOME/.dotnet/tools` (Windows: `%USERPROFILE%\.dotnet\tools`) | `dotnet-ef` or `dotnet ef` from anywhere | one version per user | | Tool-path | `dotnet tool install dotnet-ef --tool-path ./tools` | the folder you name | `./tools/dotnet-ef`, or add the folder to PATH | one version per folder | | Local | `dotnet tool install dotnet-ef` | recorded in a `dotnet-tools.json` manifest | `dotnet tool run dotnet-ef` or `dotnet ef` inside that tree | per repository | **Global** tools are user-specific, not machine-wide: another account on the same machine does not see them. The SDK adds `~/.dotnet/tools` to PATH the first time it runs, which is why a freshly installed global tool sometimes needs a new shell. **Tool-path** tools behave like global tools in a custom location. The SDK does not add that folder to PATH, so you call the tool by its full path, add the folder yourself, or run it from inside the folder. Build agents and container images use this to keep tools out of a user profile. **Local** tools are the team option. Running `dotnet tool install <id>` with neither `-g` nor `--tool-path` (you can also say `--local`) adds an entry to a **tool manifest**, a `dotnet-tools.json` file usually at the repository root. Anyone who clones the repository runs `dotnet tool restore` and gets the same versions. ## How invocation resolves 1. A global or tool-path tool is invoked by its **command name**, for example `dotnet-ef`. 2. If the command starts with `dotnet-`, the `dotnet` driver also accepts it without the prefix: `dotnet ef` finds `dotnet-ef`. 3. A local tool is always invoked through `dotnet`: `dotnet tool run dotnet-ef`, `dotnet dotnet-ef` or `dotnet ef`. 4. When a global tool and a local tool share a `dotnet-` command and you are inside the local tool's directory tree, `dotnet ef` runs the **local** one; call `dotnet-ef` directly to reach the global copy. ## Listing, updating, removing - `dotnet tool list` shows local tools for the current directory; add `-g` or `--tool-path <dir>` to see the others. - `dotnet tool update` and `dotnet tool uninstall` take the same `-g` / `--tool-path` / local choice as install. - `dotnet tool search <term>` searches NuGet.org for packages of the tool type. ## Which one to choose A developer convenience you want everywhere, such as a personal diagnostics tool, fits `-g`. Anything a build or a teammate depends on, such as the EF Core tool used to create migrations, belongs in the repository's manifest, so the version is reviewed in source control instead of depending on whatever each laptop happens to have. Tool-path installs are for machines you script, where you want the tool in a known folder without touching a user profile. ## Common mistakes - Installing a build dependency such as `dotnet-ef` globally on a CI agent: the job then depends on whatever version the image happens to carry. - Expecting `sudo dotnet tool install -g` to make a tool available to every account; it only installs for the user the command runs as. - Typing the package id instead of the command: the id and the command name can differ, and `dotnet tool list` shows both.
- Why does a newly installed global tool sometimes say 'command not found'?The SDK adds `~/.dotnet/tools` to PATH for the user on its first run, and an already-open shell has the old PATH. Opening a new shell, or adding the folder to PATH yourself on systems where the profile was not updated, fixes it.
- Can two repositories on one machine use different versions of the same tool?Yes, with local tools. Each repository's manifest pins its own version, and the SDK resolves the tool from the manifest found above the current directory. A global tool cannot do this, because one version serves every directory for that user.
A global tool is like a personal toolbox in your own car, available wherever you drive; a local tool is like the tool list taped inside a shared workshop's cabinet, so everyone who works in that room uses the same wrenches.
- Global tools are installed machine-wide for every user account.
- A --tool-path install is added to PATH automatically.
- A local tool is a project reference added to the .csproj.
- Local tools are invoked directly by their command name, without dotnet.
- .NET tools run sandboxed, so any package from a feed is safe to install.