.NET CLI tools are basically console applications with different configuration.
-
Create a console application.
dotnet new console -o MyTool
-
Write something.
Console.WriteLine($"Hello, {args[0]}!");
-
Edit .csproj file.
<ItemGroup> <PackAsTool>true</PackAsTool> <ToolCommandName>MyTool</ToolCommandName> <PackageOutputPath>./nupkg</PackageOutputPath> </ItemGroup>
-
Create a nuget package.
dotnet pack
-
Install the tool globally.
dotnet tool install --global --add-source path/to/nupkg MyTool
-
Use the tool.
dotnet MyTool "John"
Output:
Hello, John!
Top comments (0)