DEV Community

Cover image for Using dotnet tool
Alexey Ryazhskikh
Alexey Ryazhskikh

Posted on

Using dotnet tool

Dotnet tools - is a great technology to distribute command line tools.
For example, the following command installs EF Core CLI.

dotnet tool install --global dotnet-ef
Enter fullscreen mode Exit fullscreen mode

Listing installed dotnet tools:

dotnet tool list --global
Enter fullscreen mode Exit fullscreen mode

Uninstalling dotnet tool:

dotnet tool uninstall --global dotnet-ef
Enter fullscreen mode Exit fullscreen mode

You can pack your own command line application as dotnet tool:

dotnet pack MyCli.csproj --configuration Release --output ./publish`
    -p:PackAsTool=true `
    -p:ToolCommandName=mytool `
    -p:Version=1.0.0
Enter fullscreen mode Exit fullscreen mode

It generates MyCli.1.0.0.nupkg nuget package.
Built tool with be placed into tools\net7.0\any folder of the archive.
You can push the package into nuget repository as normal nuget package and install the tool from it.
But you can also install the tool from a local folder where nupkg file placed:

dotnet tool install MyCli --global --add-source ./publish
Enter fullscreen mode Exit fullscreen mode

The dotnet tool is a part of .Net Core SDK, so you can't install your tool the environment where no dotnet SDK installed. But you can install dotnet tool to environment with SDK installed and copy it from there. Check the Andey Lock example for copying dotnet tool binaries to non-sdk docker image.

Top comments (0)