A .NET 9 project template with .NET Aspire orchestration, including a sample API with tests and automated CI/CD pipelines.
- ✨ ASP.NET Core Web API - Minimal API with weather forecast endpoint
- 🚀 .NET Aspire - Modern cloud-native application orchestration
- 🧪 xUnit Tests - Integration tests using WebApplicationFactory
- 📦 Service Defaults - Shared telemetry, service discovery, and resilience patterns
- 🔄 GitHub Actions - Automated CI/CD pipelines for testing, security analysis, and releases
- 📊 Code Coverage - Integrated with Codecov for coverage tracking
- 🔒 CodeQL Analysis - Automated security scanning on every push
ProjectTemplate/
├── src/
│ ├── ProjectTemplate.Api/ # ASP.NET Core Web API
│ ├── ProjectTemplate.AppHost/ # Aspire orchestration host
│ └── ProjectTemplate.ServiceDefaults/ # Shared configuration and services
├── tests/
│ └── ProjectTemplate.Tests/ # Integration tests
├── .github/
│ └── workflows/
│ ├── ci.yml # Build and test on PR
│ ├── codeql-analysis.yml # Security analysis
│ └── release.yml # Release and publish to NuGet
└── Directory.Build.props # Shared build properties and versioning
- .NET 9 SDK
- Docker Desktop (for Aspire Dashboard)
-
Install the .NET Aspire workload:
dotnet workload install aspire
-
Clone the repository:
git clone https://github.com/your-username/your-repository.git cd your-repository -
Restore dependencies:
dotnet restore
This will start the API and open the Aspire Dashboard:
dotnet run --project src/ProjectTemplate.AppHostThe Aspire Dashboard will be available at the URL shown in the console output (typically http://localhost:15888).
dotnet run --project src/ProjectTemplate.ApiThe API will be available at:
- HTTP:
http://localhost:5000 - HTTPS:
https://localhost:5001
dotnet testdotnet build --configuration Release- GET
/weatherforecast- Returns a 5-day weather forecast
- GET
/health- Health check endpoint - GET
/alive- Liveness probe - GET
/metrics- Prometheus metrics
- Create a new project in the
srcfolder - Reference
ProjectTemplate.ServiceDefaultsto get shared configurations - Add the project to the AppHost in
src/ProjectTemplate.AppHost/Program.cs:
var myService = builder.AddProject<Projects.MyService>("myservice");The project includes two types of tests:
- WebApplicationFactory Tests - Run in any environment (CI/CD friendly)
- Aspire Integration Tests - Require the DCP (Development Control Plane), skipped in CI
Runs on every pull request and push to main:
- Builds the solution
- Runs all tests
- Collects code coverage
- Uploads coverage to Codecov
Runs on:
- Every push to main
- Every pull request
- Weekly schedule (Monday at midnight)
Performs automated security scanning to detect vulnerabilities.
Runs on push to main:
- Builds and tests the solution
- Packs NuGet packages
- Publishes to NuGet.org (requires
NUGET_API_KEYsecret) - Creates GitHub release with auto-generated release notes
- Tags the release
Version is managed in Directory.Build.props:
<Version>1.0.0</Version>Update this version to release new versions to NuGet.
To enable the full CI/CD pipeline, configure these secrets in your GitHub repository:
Note: These secrets are only required if you want to publish NuGet packages or track code coverage. The CI workflow will work without them for development and testing purposes.
NUGET_API_KEY- API key for publishing to NuGet.org (required only for publishing packages)- Get your API key from NuGet.org
CODECOV_TOKEN- Token for uploading coverage to Codecov (optional, for coverage tracking)- Get your token from Codecov after connecting your repository
MIT
Contributions are welcome! Please feel free to submit a Pull Request.