AgentSkillsCN

dotnet-aspire-starter

创建生产就绪的 .NET 10 Aspire 项目,配备 ASP.NET MVC + Razor + TypeScript 前端、REST API 后端、Entity Framework、OpenTelemetry 可观测性,以及 Polly 弹性框架。当用户要求新建 .NET Web 应用程序、搭建 .NET Aspire 项目、构建包含前端与 API 的全栈 .NET 解决方案、为 .NET 配置 OpenTelemetry、引入 Polly 弹性模式,或以现代最佳实践启动一个新的 C# 项目时,可优先选用此方案。同时支持 OIDC 认证的准备工作,以及面向 Grafana 的遥测配置。

SKILL.md
--- frontmatter
name: dotnet-aspire-starter
description: Creates production-ready .NET 10 Aspire projects with ASP.NET MVC + Razor + TypeScript frontend, REST API backend, Entity Framework, OpenTelemetry observability, and Polly resilience. Use when asked to create a new .NET web application, scaffold a .NET Aspire project, set up a full-stack .NET solution with frontend and API, configure OpenTelemetry for .NET, add Polly resilience patterns, or start a new C# project with modern best practices. Supports OIDC authentication preparation and Grafana-ready telemetry.

.NET Aspire Starter

Create production-ready .NET 10 Aspire projects with minimal friction. This skill transforms a project idea into a fully configured solution with frontend, backend API, database access, observability, and resilience patterns.

What This Skill Creates

A complete .NET Aspire solution including:

LayerTechnologyPurpose
Orchestrator.NET AspireService orchestration, local development, cloud deployment
FrontendASP.NET MVC + Razor + TypeScript + CSSUser-facing web application
Backend APIASP.NET MVC REST APIBusiness logic and data access
DatabaseEntity Framework CoreORM with code-first migrations
ObservabilityOpenTelemetry + OTLPLogs, metrics, traces (Grafana-ready)
ResiliencePolly.NETCircuit breakers, retries, timeouts
AuthenticationOIDC (prepared)Ready-to-enable identity integration

Quick Start Workflow

User provides: A project idea (e.g., "Build me a task management app")

This skill creates: A complete .NET solution ready for feature development

Step 1: Gather Project Details

Ask the user for:

  1. Project name (e.g., "TaskManager", "InventoryTracker")
  2. Brief description (1-2 sentences)
  3. Target output path (where to create the solution)

Step 2: Run the Scaffold Script

The scaffolder creates a base .NET Aspire project using the official template, then adds skill-specific enhancements (coding standards, AI context, VS Code configuration).

bash
# Run as a C# script directly (no compilation needed)
dotnet run scripts/ScaffoldAspireProject/Program.cs -- \
  --name "TaskManager" \
  --description "A task management application for teams" \
  --output "./projects"

Or build once and reuse the executable:

bash
# Build the scaffolder (first time only)
dotnet build scripts/ScaffoldAspireProject/ScaffoldAspireProject.csproj -c Release

# Run the compiled executable
./scripts/ScaffoldAspireProject/bin/Release/net10.0/ScaffoldAspireProject \
  --name "TaskManager" \
  --description "A task management application for teams" \
  --output "./projects"

Step 3: Initial Configuration

After scaffolding, guide the user through:

  1. Database connection: Update appsettings.json with connection string
  2. Initial entity model: Create the first domain entity in the API project
  3. First migration: Run dotnet ef migrations add Initial

See Initial Setup Guide for detailed steps.

Step 4: Begin Feature Development

The user can now focus on their idea. The boilerplate is complete:

  • Create entities in {ProjectName}.Api/Models/
  • Add controllers in {ProjectName}.Api/Controllers/
  • Create views in {ProjectName}.Web/Views/
  • Write TypeScript in {ProjectName}.Web/Scripts/

How It Works

The scaffolder in two steps:

  1. Base Project Creation: Runs dotnet new aspire-starter with your project name

    • Creates official Microsoft Aspire project structure
    • Generates AppHost, ServiceDefaults, Api, and Web projects
    • Includes OpenTelemetry and Polly integration
  2. Skill-Specific Enhancements: Adds on top:

    • Coding Standards: .editorconfig and Directory.Build.props with Microsoft C# conventions
    • AI Context: .github/copilot-instructions.md and docs/ARCHITECTURE.md for GitHub Copilot/Claude
    • Developer Experience: VS Code configuration for debugging and build tasks

This approach keeps you aligned with Microsoft's official template while adding production-ready context and standards.


Project Structure

The scaffold creates this structure (plus everything from dotnet new aspire-starter):

code
{ProjectName}/
├── {ProjectName}.sln
├── {ProjectName}.AppHost/              # Aspire orchestrator (from template)
├── {ProjectName}.ServiceDefaults/      # Shared config (from template)
├── {ProjectName}.Api/                  # REST API backend (from template)
├── {ProjectName}.Web/                  # MVC + Razor frontend (from template)
├── Directory.Build.props                # Our: Microsoft coding standards
├── .editorconfig                        # Our: Code style enforcement
├── .github/
│   └── copilot-instructions.md         # Our: AI coding context
├── .vscode/
│   ├── settings.json                   # Our: VS Code config
│   ├── launch.json                     # Our: Debug configuration
│   └── tasks.json                      # Our: Build tasks
└── docs/
    └── ARCHITECTURE.md                 # Our: Architecture reference

Feature Configuration

OpenTelemetry (Enabled by Default)

Template includes full OpenTelemetry setup. See Telemetry Setup for:

  • Enabling Grafana integration
  • Custom metrics and traces
  • Structured logging patterns
  • Production configuration

Polly Resilience (Enabled by Default)

Template includes Microsoft.Extensions.Http.Resilience with sensible defaults. See Polly Configuration for:

  • Default circuit breaker thresholds
  • Retry policies
  • Timeout configuration
  • Custom resilience strategies

OIDC Authentication (Prepared, Not Enabled)

Authentication scaffolding is in place but commented out. See OIDC Preparation for:

  • Enabling OIDC in frontend and API
  • Shared authentication between layers
  • Token propagation patterns
  • Provider-specific setup (Azure AD, Auth0, Keycloak)

Coding Standards

This skill enforces Microsoft coding standards via:

  • EditorConfig: Consistent formatting across IDEs
  • .NET Analyzers: Enabled with TreatWarningsAsErrors
  • Nullable Reference Types: Enabled by default

See Coding Standards Reference for the complete style guide.


Development Commands

After scaffolding, these commands are available:

bash
# Run the full solution (frontend + API + database)
dotnet run --project {ProjectName}.AppHost

# Run migrations
dotnet ef migrations add {MigrationName} --project {ProjectName}.Api
dotnet ef database update --project {ProjectName}.Api

# Build TypeScript
npm run build --prefix {ProjectName}.Web

# Watch TypeScript during development
npm run watch --prefix {ProjectName}.Web

# Run tests
dotnet test

VS Code & Visual Studio Template Usage

For maximum reuse, this skill can generate templates for direct IDE use.

VS Code Custom Snippets

The scaffold creates .vscode/ configurations including:

  • Launch configurations for debugging
  • Task runners for build/watch
  • Recommended extensions

Visual Studio Template Export

To create a reusable VS template from the scaffolded project:

bash
dotnet new --install ./{ProjectName}/ --force

This registers the project as a dotnet new template. See Template Export Guide for multi-project template creation.


Maximizing AI Assistant Effectiveness

The scaffold creates documentation that provides context for AI coding assistants:

GitHub Copilot

The generated .github/copilot-instructions.md provides:

  • Solution architecture overview
  • Coding patterns used in the project
  • Entity/controller/view conventions
  • Testing patterns

Claude / Claude Code

The generated docs/ARCHITECTURE.md serves as context for:

  • Understanding project structure
  • Following established patterns
  • Maintaining consistency across features

Recommendation: When starting new features, reference these files in your prompts to maintain consistency.


References


Troubleshooting

Script Execution Issues

Missing .NET SDK or old version:

bash
# Check version (need .NET 10.0+)
dotnet --version

# Install from https://dotnet.microsoft.com/download

dotnet new aspire-starter template not found:

bash
# Update .NET and workload
dotnet workload update
dotnet workload install aspire
dotnet new --list | grep aspire  # Verify installation

Restore dependencies:

bash
cd scripts/ScaffoldAspireProject
dotnet restore

Build Errors After Scaffold

Missing workload error:

bash
dotnet workload install aspire

TypeScript compilation errors:

bash
cd {ProjectName}.Web && npm install

Database Connection Issues

Ensure the connection string in appsettings.json matches your database. For local development, the scaffold defaults to SQLite.