Using the .NET CLI Tool
The .NET CLI (Command-Line Interface) provides a way to create, build, and manage .NET applications directly from a terminal. With project templates and code scaffolding, developers can automate repetitive setup tasks and generate consistent application structures without manually creating every file.
Nano ASP.NET Boilerplate extends this workflow with custom .NET templates for generating complete application solutions, CRUD services, and API controllers. You can configure a new project with your preferred multi-tenancy and frontend options, then use the CLI to scaffold additional functionality as your application grows.
After installing the Nano.Boilerplate NuGet package, you can use these templates from the command line or select the Nano Boilerplate template in Visual Studio.
Nano Project (project template) Using the CLI Tool
Here is a quick reference tool for the cli commands:
Creating New Projects
Use the following command to generate a new project from the Nano Boilerplate template:
dotnet new nano
To specify a name for your project, use the -n parameter:
dotnet new nano -n MyApp
Replace MyApp with your desired application name.
To view the available parameters and options, run:
dotnet new nano -h
Multi-Tenancy Configuration
The -m parameter specifies the multi-tenancy configuration for the generated application.
| Option | Description |
|---|---|
multidb | Multi-tenancy with a separate database for each tenant |
singledb | Multi-tenancy with multiple tenants sharing a database |
singletenant | Single-tenant application without multi-tenancy |
If you don’t specify the -m parameter, Nano uses multidb by default.
For more information about the differences between these configurations, see the documentation on multi-tenancy.
Frontend Configuration
The -ui parameter specifies the frontend configuration for the generated project.
| Option | Description |
|---|---|
spa | Single-page application setup for a frontend such as React or Vue |
razor | Server-rendered Razor Pages setup |
The default is spa. Choose this option when building a single-page application with React, Vue, or another SPA framework.
The razor option configures the project for a server-rendered interface using Razor Pages.
Note: The -ui parameter is available in the full version of the Nano Boilerplate.
You can also create a project through Visual Studio by selecting Nano Boilerplate from the installed project templates.
Generating CRUD Services
Nano includes a template for generating application services with common create, read, update, and delete (CRUD) operations. This reduces repetitive coding when adding new entities to your application.
Use the following command to generate a service:
dotnet new nano-service
Run the command from the directory where you want the service to be created. Typically, this is the Application/Services directory within your solution.
The service template accepts the following parameters:
-s— The singular name of the entity.-p— The plural name used for collections and related operations.-ap— The name of your application.
For example, to generate a service for managing suppliers in an application named MyApp, run:
dotnet new nano-service -s Supplier -p Suppliers -ap MyApp
The template generates a folder containing the service class, interface, DTOs, filters, and specifications required by the service implementation.
These generated components provide a consistent starting point for implementing CRUD functionality. You can then customize the service to accommodate your application’s validation rules, business logic, and data requirements.
Generating Services for Razor Pages
If your application uses Razor Pages, include the -ui razor parameter when generating the service:
dotnet new nano-service -s Supplier -p Suppliers -ap MyApp -ui razor
This configures the generated service for the Razor Pages setup, including the appropriate pagination endpoint.
Generating API Controllers
Nano also provides a controller template for creating API controllers within an existing application.
To generate a controller, run:
dotnet new nano-controller
Navigate to the directory where you want the controller to be created. For a Web API project, this is typically WebApi/Controllers. For a Razor-based application, it may be RazorApp/Controllers.
As with the service template, specify the singular entity name, plural entity name, and application name using the -s, -p, and -ap parameters.
For example:
dotnet new nano-controller -s Supplier -p Suppliers -ap MyApp
This generates an API controller in the current directory, providing a starting point for exposing your application’s service functionality through HTTP endpoints.
Generating Controllers for Razor Pages
When generating a controller for an application using Razor Pages, you can include the -ui razor parameter to configure the appropriate pagination endpoint:
dotnet new nano-controller -s Supplier -p Suppliers -ap MyApp -ui razor
Review the generated code and adapt it to your application’s requirements before using it in production.
Recommended Workflow
A typical workflow when starting a new Nano application is:
- Install the Nano.Boilerplate NuGet package.
- Generate a new application using
dotnet new nano. - Select the appropriate multi-tenancy and frontend configuration.
- Configure the database connection and run the application.
- Use
dotnet new nano-serviceto scaffold CRUD services for new entities. - Use
dotnet new nano-controllerto generate API controllers for those services. - Customize the generated code to implement your application’s business requirements.
Using the Nano CLI templates helps maintain a consistent application structure while reducing the amount of repetitive code you need to write manually.
Video Guide
Next Steps
Learn about the .NET back-end in the Solution Overview guide