. Net Core 2.1 introduces a new feature, the essence of which is the NuGet package that contains the console application, and for now, there are no particularly useful tools, but it is believed that over time, a variety of creative or practical Global Tools will appear in everyone's eyes.
Installing a global tools is simple, enter a command dotnet tool install -g dotnetsay
, the tool named Dotnetsay is already installed in a specific directory.
OS |
Path |
Linux/macos |
$HOME/.dotnet/tools |
Windows |
%userprofile%.dotnet\tools |
If you want to use a tool, you need to enter the command for the tool, such as dotnetsay
:
While global tools is part of the NuGet package, it is difficult to find out the many NuGet packages because the NuGet Web site does not specifically classify it, so it is not known by its name. A better approach is to find the tools you need in GitHub's Natemcmaster/dotnet-tools library.
Thick and thick, such as dotnet-serve,dotnet-search,dotnet-md5 and other individuals think it is very useful.
However, some tools will display errors that are not found in the specified version of the framework after the installation is complete. Global tools has yet to be improved in terms of compatibility.
It's not difficult to create a global tools yourself.
Because global tools is actually a console application, the first is the new one. dotnet new consoel -o helloGlobalTools
.
The code content is simple, displaying a string of characters containing the current time:
using System;namespace helloGlobalTools{ class Program { static void Main(string[] args) { Console.WriteLine($"Hello {DateTime.Now}"); } }}
You need to join within the PropertyGroup node in the csproj file <PackAsTool>true</PackAsTool>
.
dotnet pack
the HELLOGLOBALTOOLS.1.0.0.NUPKG installation package file can be generated under the Bin\Debug directory by command.
Switch the current directory to the path to the file, and then execute the Global Tools installation command dotnet tool install -g helloGlobalTools --add-source ./
. After the installation is complete, you can also dotnet tool list -g
confirm that the installation was successful.
Finally, enter your tool command name to get the desired result.
Of course, if you have confidence in your work and want to share it with others, you can upload the NuGet package to Nuget.org's official website. The result of your labor will be able to maximize the value of the play.
Reference Documentation:
Global-tools
. Net Core Development Log--global Tools