How to create your own .NET CLI tools with Tye

M. Haris Tauqir
Awesome .Net
Published in
3 min readAug 14, 2022

--

source: Stackify

Project Tye is an experimental tool to automate, manage and run microservices with one command.

If you are working on microservices, it is very difficult to run multiple projects especially if you have a front end that communicates with multiple back ends. It also provides you a dashboard to see the state of running services, addresses, logs, and many other things. You can read more about it here.

In this blog, we are gonna see how Tye can help us make CLI tools for our own use. CLI tools are developers' friends. I love working with CLI tools since I work with .net on my MacOs.

Installation

To get started, you first have to install .Net 6.0 on your machine.

  1. You have to install Tye as a global tool using this command:
dotnet tool install --global Microsoft.Tye --version 0.11.0-alpha.22111.1

2. Verify if it is installed correctly using the following command

dotnet tool list -g

Project Setup

I have already set up a project which will take the city name as input and return the current weather report.

For this, I have used the free Rapid Open Weather API platform to return the actual data. I am gonna remove my API key from the repo, so if you want to test the code, follow these steps.

  1. Sign up on Rapid
  2. Subscribe to World Weather API
  3. Copy the Key URI, Host, and key in the code.

Once this is all set up and ready. Run the project and enter the city name. It should return you the current weather of the entered city.

Generating Nuget Package

Copy the following two lines in the project properties as shown in the image below.

<ToolCommandName>weather</ToolCommandName>
<PackageOutputPath>./nupackage</PackageOutputPath>

<ToolCommandName> takes the name of the tool command and <PackageOutputPath> is the path to generate the NuGet packages.

Open the terminal and set the path to the project directory. Now everything is set up we have to generate a NuGet package file and install it.

To generate a NuGet package run the following command

Dotnet pack

Once this command is successful, you will see a nupackage folder as specified in the <PackageOutputPath> in your project directory.

Now install the package globally on your machine so you can use your CLI tool.

dotnet tool install -g --add-source ./nupackage Dotnet.CliTool

Now run the weather command with any city name to see the weather report. Keep in mind, that the ‘weather’ command was specified in the <ToolCommandName> property. You can name it whatever you like.

Conclusion

In this blog, we created our own weather CLI tool with Tye. You can create your own CLI tools with this awesome library. You can also publish your CLI packages on NuGet. Just sign up on the platform and upload the package file.

Download source code: https://github.com/haristauqir/Dotnet.CliTool

--

--

M. Haris Tauqir
Awesome .Net

A software developer who loves learning how things work…