Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
This article applies to: ✔️ .NET 8 SDK and later versions
This tutorial shows you how to install and use a global tool. The tool you use is the one you create in the first tutorial of this series.
Prerequisites
- Complete the first tutorial of this series.
- .NET 10.0.100 SDK or later (for
dnx) - optional but recommended.
Run the tool without installation (recommended)
Starting with .NET 10.0.100, you can run .NET tools without permanent installation using dnx:
Run the tool directly using dnx (simplified syntax):
dnx dotnet-env --add-source ./nupkgThe
--add-sourceparameter tells the .NET CLI to use the ./nupkg directory as an additional source feed for NuGet packages when the tool isn't available on NuGet.org.
Use the tool as a global tool (traditional installation)
If you prefer permanent installation for frequent use:
Install the tool from the package by running the dotnet tool install command in the dotnet-env project folder:
dotnet tool install --global --add-source ./nupkg dotnet-envThe
--globalparameter tells the .NET CLI to install the tool binaries in a default location that's automatically added to thePATHenvironment variable.The
--add-sourceparameter tells the .NET CLI to temporarily use the ./nupkg directory as an additional source feed for NuGet packages. You gave your package a unique name to make sure it's only found in the ./nupkg directory, not on NuGet.org.The output shows the command used to call the tool and the version installed:
You can invoke the tool using the following command: dotnet-env Tool 'dotnet-env' (version '1.0.0') was successfully installed.Note
By default the architecture of the .NET binaries to install represents the currently running OS architecture. To specify a different OS architecture, see dotnet tool install, --arch option.
Invoke the tool:
dotnet-envNote
If the command fails, open a new terminal to refresh the
PATHenvironment variable.Remove the tool by running the dotnet tool uninstall command:
dotnet tool uninstall -g dotnet-env
Use the tool as a global tool installed in a custom location
Install the tool from the package.
On Windows:
dotnet tool install --tool-path c:\dotnet-tools --add-source ./nupkg dotnet-envOn Linux or macOS:
dotnet tool install --tool-path ~/bin --add-source ./nupkg dotnet-envThe
--tool-pathparameter tells the .NET CLI to install the tool binaries in the specified location. If the directory doesn't exist, it's created. The directory isn't automatically added to thePATHenvironment variable.The output shows the command used to call the tool and the version installed:
You can invoke the tool using the following command: dotnet-env Tool 'dotnet-env' (version '1.0.0') was successfully installed.Invoke the tool:
On Windows:
c:\dotnet-tools\dotnet-envOn Linux or macOS:
~/bin/dotnet-envRemove the tool by running the dotnet tool uninstall command:
On Windows:
dotnet tool uninstall --tool-path c:\dotnet-tools dotnet-envOn Linux or macOS:
dotnet tool uninstall --tool-path ~/bin dotnet-env
Troubleshoot
If you get an error message while following the tutorial, see Troubleshoot .NET tool usage issues.
Next steps
In this tutorial, you installed and used a tool as a global tool. For more information on installing and using global tools, see Managing global tools. To install and use the same tool as a local tool, advance to the next tutorial.