Table of Contents
Introduction
I this post we will see how to create a cli for you .Net application.
Why?
Sometimes when I am working on a project and I need to do some repetitive tasks, I create a cli for that. For example, Importing data from a csv file to the database. this is a repetitive task and I don't want to do it manually every time. But I don't want to create a UI for that. for these cases CLI can be very useful.
Installation
First we need to install the .net template.
dotnet new install Anto.Cli.Template
Creating a new project
Now we can create a new project using the template.
dotnet new cli-template -o MyProject --api myabpproject.com
this will create a new project in the MyProject folder. The default project comes with few sample commands.
Adding a new command
you can use the plop generator to add a new command.
plop
this will ask you for the command name. make sure you install the npm packages before running the plop command.
npm install
Running the project
you can run the project using the following command.
dotnet run -- --help
This will show you the list of commands.
Data Seeding
I have created 2 data seeding commands. one for the users and one for the tenants. These will seed random data to you application after you login. you can remove these commands if you don't need them. I have created them for my personal use.
Conclusion
This is a very simple template. you can add more commands to it. I will add more commands to it in the future. I created this template to seed some data to my application after I login. I hope you find this useful. let me know if you have any questions.
Related Posts
Modern API Documentation in .NET with Scalar and OpenAPI
Learn how to implement beautiful API documentation using Scalar and OpenAPI in .NET 9.0
Building an AI-Powered .NET API with Ollama and Microsoft.Extensions.AI
Learn how to create an intelligent .NET API using Ollama, Microsoft.Extensions.AI, and implement function calling capabilities with Large Language Models.
OpenID Connect with Next.js 15 and openid-client 6
A guide to implementing secure authentication using OpenID Connect in Next.js 15 with the openid-client library version 6