DEV Community

Dominic Pascasio
Dominic Pascasio

Posted on • Edited on

1

.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)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay