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

Common Options

Examples

Create a Console Application

nmbl new console --name MyConsoleApp

Creates a new console application.

Create a Web API Project

nmbl new webapi --name MyApi --output src/MyApi

Creates a Web API project in the specified directory.

Create a Class Library

nmbl new classlib --name MyLibrary --output src/MyLibrary

Creates a class library project.

Create a Solution File

nmbl new sln --name MySolution

Creates a new .slnx solution file.

Create xUnit Test Project

nmbl new xunit --name MyProject.Tests --output tests/MyProject.Tests

Creates 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 MyWorker

Library Templates

# Class library
nmbl new classlib --name MyLibrary

# Razor Class Library
nmbl new razorclasslib --name MyRazorLib

Test Templates

# xUnit test project
nmbl new xunit --name MyTests

# NUnit test project
nmbl new nunit --name MyTests

# MSTest project
nmbl new mstest --name MyTests

Solution Template

# Solution file (.slnx)
nmbl new sln --name MySolution

Use 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.csproj

Microservices 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 NotificationService

Library 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.csproj

Adding 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.csproj

Template Management

List Available Templates

nmbl new --list

Shows all available templates.

Search for Templates

nmbl new --search webapi

Searches 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 --help

Example: Web API with Options

nmbl new webapi \
  --name MyApi \
  --output src/MyApi \
  --framework net10.0 \
  --auth Individual \
  --use-controllers

Creates a Web API with authentication and controllers.

Dry Run

nmbl new console --name TestApp --dry-run

Shows 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.IntegrationTests

Tips

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'