Skip to main content

One shot tool execution in .NET 10 - Run tools without installing

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:

  1. 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.
  2. Download: The tool package is downloaded to the global NuGet package cache (the same location used for all NuGet packages).
  3. Execution: Unlike dotnet tool install, the package is run directly from the cache without creating a persistent tool store entry or PATH shim.
  4. 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

Popular posts from this blog

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.

.NET 8–Keyed/Named Services

A feature that a lot of IoC container libraries support but that was missing in the default DI container provided by Microsoft is the support for Keyed or Named Services. This feature allows you to register the same type multiple times using different names, allowing you to resolve a specific instance based on the circumstances. Although there is some controversy if supporting this feature is a good idea or not, it certainly can be handy. To support this feature a new interface IKeyedServiceProvider got introduced in .NET 8 providing 2 new methods on our ServiceProvider instance: object? GetKeyedService(Type serviceType, object? serviceKey); object GetRequiredKeyedService(Type serviceType, object? serviceKey); To use it, we need to register our service using one of the new extension methods: Resolving the service can be done either through the FromKeyedServices attribute: or by injecting the IKeyedServiceProvider interface and calling the GetRequiredKeyedServic...

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t...