NET 10 introduces a new feature for developers: one-shot tool execution. If you've ever needed to quickly run a .NET tool for a CI/CD pipeline, a one-off script, or just to try something out without cluttering your system with globally installed tools, this feature is for you.
What is one-shot tool execution?
One-shot tool execution allows you to run .NET tools directly without installing them globally or locally on your machine. Instead of the traditional two-step process of installing and then running a tool, you can now execute it in a single command.
Some use case where I think you could use this feature :
- CI/CD pipelines where you want clean, reproducible builds
- Ephemeral environments like containers or temporary build agents
- Quick experimentation with tools before committing to installation
- Scripts and automation that need specific tools without side effects
The traditional way vs. one-shot execution
Previously, to use a .NET tool, you'd need to install it first:
# Install the tool globally
dotnet tool install -g dotnetsay
# Then run it
dotnetsay "Hello, World!"
This would download the package, install it to ~/.dotnet/tools/.store, create an executable shim in ~/.dotnet/tools, and add it to your PATH. While this works great for tools you use regularly, it's overkill for one-time usage.
With .NET 10, you can execute tools on the fly:
dotnet tool exec dotnetsay "Hello, World!"
When you run this command, you'll see a confirmation prompt:
Tool package dotnetsay@1.0.0 will be downloaded from source <source>.
Proceed? [y/n] (y): y
After confirming, the tool downloads and runs immediately without being "installed" in the traditional sense.
How it works under the hood
When you use dotnet tool exec, the following happens:
- Version Resolution: If you don't specify a version, the command first checks for a local tool manifest (
.config/dotnet-tools.json). If the tool exists there, it uses that version. Otherwise, it fetches the latest from NuGet.org. - Download: The tool package is downloaded to the global NuGet package cache (the same location used for all NuGet packages).
- Execution: Unlike
dotnet tool install, the package is run directly from the cache without creating a persistent tool store entry or PATH shim. - No Persistence: Once execution completes, there's no lingering installation—just the cached package that's shared with other NuGet operations.
The dnx shortcut
Similar to npx, .NET 10 introduces the dnx command (a lightweight wrapper script):
dnx dotnetsay "Hello, World!"
The dnx script simply forwards arguments to dotnet tool exec, making the command shorter and more intuitive. It's implemented as a shell script that calls into the .NET CLI, allowing its behavior to evolve with future SDK updates.
You have full control over which version of a tool to execute:
# Run a specific version dotnet tool exec dotnetsay@1.0.0 "Hello!" # Run from a specific package source dotnet tool exec --add-source https://api.nuget.org/v3/index.json dotnetsay
Conclusion
For tools you use frequently in your daily development workflow, traditional installation (dotnet tool install -g) is still the better choice.But when you are building CI/CD pipelines, working in containerized environments, or just want to try out a tool without commitment, dotnet tool exec and dnx provide the perfect solution.
It's a small feature that makes a big difference in developer experience.
More information
What's new in the SDK and tooling for .NET 10 | Microsoft Learn
