new - Create New Projects
Overview
The new command creates new .NET projects using templates. It’s a wrapper around dotnet new with enhanced functionality and nmbl-specific templates. This command helps you quickly scaffold new projects with best practices and standard configurations.
Syntax
nmbl new <template> [options]Arguments
template- Template name or short name (e.g., console, webapi, classlib, solution)
Common Options
--name <name>or-n <name>- Name for the output--output <path>or-o <path>- Output directory--force- Force creation even if files would be overwritten--dry-run- Display what would happen without making changes
Examples
Create a Console Application
nmbl new console --name MyConsoleAppCreates a new console application.
Create a Web API Project
nmbl new webapi --name MyApi --output src/MyApiCreates a Web API project in the specified directory.
Create a Class Library
nmbl new classlib --name MyLibrary --output src/MyLibraryCreates a class library project.
Create a Solution File
nmbl new sln --name MySolutionCreates a new .slnx solution file.
Create xUnit Test Project
nmbl new xunit --name MyProject.Tests --output tests/MyProject.TestsCreates a unit test project using xUnit.
Common Templates
Application Templates
# Console application
nmbl new console --name MyApp
# Web API
nmbl new webapi --name MyApi
# Blazor WebAssembly
nmbl new blazorwasm --name MyBlazorApp
# ASP.NET Core Web App (Razor Pages)
nmbl new webapp --name MyWebApp
# Worker Service
nmbl new worker --name MyWorkerLibrary Templates
# Class library
nmbl new classlib --name MyLibrary
# Razor Class Library
nmbl new razorclasslib --name MyRazorLibTest Templates
# xUnit test project
nmbl new xunit --name MyTests
# NUnit test project
nmbl new nunit --name MyTests
# MSTest project
nmbl new mstest --name MyTestsSolution Template
# Solution file (.slnx)
nmbl new sln --name MySolutionUse Cases
Starting a New Project
# Create solution and projects
nmbl new sln --name MySolution
cd MySolution
nmbl new webapi --name MyApi --output src/MyApi
nmbl new classlib --name MyCore --output src/MyCore
nmbl new xunit --name MyApi.Tests --output tests/MyApi.Tests
# Add projects to solution
dotnet sln add src/MyApi/MyApi.csproj
dotnet sln add src/MyCore/MyCore.csproj
dotnet sln add tests/MyApi.Tests/MyApi.Tests.csprojMicroservices Scaffold
mkdir services
cd services
# Create multiple services
nmbl new webapi --name UserService --output UserService
nmbl new webapi --name OrderService --output OrderService
nmbl new webapi --name NotificationService --output NotificationServiceLibrary Development
# Create library structure
nmbl new sln --name MyLibrary
mkdir src tests
nmbl new classlib --name MyLibrary --output src/MyLibrary
nmbl new xunit --name MyLibrary.Tests --output tests/MyLibrary.Tests
dotnet sln add src/MyLibrary/MyLibrary.csproj
dotnet sln add tests/MyLibrary.Tests/MyLibrary.Tests.csproj
cd tests/MyLibrary.Tests
dotnet add reference ../../src/MyLibrary/MyLibrary.csprojAdding to Existing Solution
# Create new project in existing solution
nmbl new classlib --name MyNewFeature --output src/MyNewFeature
# Add to solution
dotnet sln add src/MyNewFeature/MyNewFeature.csprojTemplate Management
List Available Templates
nmbl new --listShows all available templates.
Search for Templates
nmbl new --search webapiSearches for templates matching “webapi”.
Install Custom Templates
# Install a template package
dotnet new install <package-name>
# Then use with nmbl new
nmbl new <template-name>Advanced Usage
Template Options
Different templates have different options. Get help for a specific template:
nmbl new webapi --helpExample: Web API with Options
nmbl new webapi \
--name MyApi \
--output src/MyApi \
--framework net10.0 \
--auth Individual \
--use-controllersCreates a Web API with authentication and controllers.
Dry Run
nmbl new console --name TestApp --dry-runShows what would be created without actually creating files.
Project Structure Best Practices
Clean Architecture
# Create clean architecture structure
nmbl new sln --name MyApp
mkdir -p src/MyApp.Domain
mkdir -p src/MyApp.Application
mkdir -p src/MyApp.Infrastructure
mkdir -p src/MyApp.Web
mkdir -p tests/MyApp.UnitTests
mkdir -p tests/MyApp.IntegrationTests
nmbl new classlib --name MyApp.Domain --output src/MyApp.Domain
nmbl new classlib --name MyApp.Application --output src/MyApp.Application
nmbl new classlib --name MyApp.Infrastructure --output src/MyApp.Infrastructure
nmbl new webapi --name MyApp.Web --output src/MyApp.Web
nmbl new xunit --name MyApp.UnitTests --output tests/MyApp.UnitTests
nmbl new xunit --name MyApp.IntegrationTests --output tests/MyApp.IntegrationTestsTips
Create Project Template Script
#!/bin/bash
# create-service.sh - Template for creating a microservice
NAME=$1
if [ -z "$NAME" ]; then
echo "Usage: ./create-service.sh ServiceName"
exit 1
fi
nmbl new webapi --name "$NAME" --output "services/$NAME"
nmbl new xunit --name "$NAME.Tests" --output "tests/$NAME.Tests"
cd "tests/$NAME.Tests"
dotnet add reference "../../services/$NAME/$NAME.csproj"
echo "Service $NAME created successfully"Automate Setup
# Add to your dotfiles or team setup scripts
alias new-api='nmbl new webapi --framework net10.0'
alias new-lib='nmbl new classlib --framework net10.0'
alias new-test='nmbl new xunit --framework net10.0'Related Commands
- No direct related nmbl commands (this wraps dotnet new)
- Use
dotnet slnto manage solution files - Use
dotnet add referenceto add project references