DEV Community

Dominic Pascasio
Dominic Pascasio

Posted on • Updated on

.NET - Create a Simple CLI Tool

.NET CLI tools are basically console applications with different configuration.

  1. Create a console application.

    dotnet new console -o MyTool
    
  2. Write something.

    Console.WriteLine($"Hello, {args[0]}!");
    
  3. Edit .csproj file.

    <ItemGroup>
        <PackAsTool>true</PackAsTool>
        <ToolCommandName>MyTool</ToolCommandName>
        <PackageOutputPath>./nupkg</PackageOutputPath>
    </ItemGroup>
    
  4. Create a nuget package.

    dotnet pack
    
  5. Install the tool globally.

    dotnet tool install --global --add-source path/to/nupkg MyTool    
    
  6. Use the tool.

    dotnet MyTool "John"
    

    Output:

    Hello, John!
    

Resource

Microsoft Docs

Top comments (0)