Skip to content

BenjaminMichaelis/DotnetTemplates

Repository files navigation

Dotnet Templates

This repository contains opinionated dotnet new templates, published as the BenjaminMichaelis.Dotnet.Templates NuGet template pack.

Feedback and contributions are welcome via issues and pull requests.

Requirements

Use .NET 10 SDK or newer.

Install

Install the template pack:

> dotnet new install BenjaminMichaelis.Dotnet.Templates

Create a project from a template:

> dotnet new bmichaelis.{template-name}

Example:

> dotnet new bmichaelis.nuget

Included templates

Use the short name after bmichaelis.:

Short name Template docs
nuget templates/Library/NuGet
tool templates/Library/DotnetTool
quickstart.consoleapp templates/Quickstart/ConsoleApp
quickstart.benchmarkconsole templates/Quickstart/BenchmarkApp
aspire.minimalapi templates/Aspire/MinimalApi

Update installed templates

> dotnet new update

Uninstall

> dotnet new uninstall BenjaminMichaelis.Dotnet.Templates

Local testing

Build the local package:

> dotnet pack --configuration Release -o .

Install the local package:

> dotnet new install .\BenjaminMichaelis.Dotnet.Templates.*.nupkg --force

Generate and validate:

> dotnet new bmichaelis.{template-name}
> dotnet build
> dotnet test --no-build
> dotnet publish --no-build

Remove the local install:

> dotnet new uninstall .\BenjaminMichaelis.Dotnet.Templates.*.nupkg

Repository layout

  • Templates.csproj: template pack project that packs templates/**
  • templates/Library/NuGet: bmichaelis.nuget
  • templates/Library/DotnetTool: bmichaelis.tool
  • templates/Quickstart/ConsoleApp: bmichaelis.quickstart.consoleapp
  • templates/Quickstart/BenchmarkApp: bmichaelis.quickstart.benchmarkconsole
  • templates/Aspire/MinimalApi: bmichaelis.aspire.minimalapi

Adding a new template

  1. Add the template files under templates/
  2. Add or update .template.config/template.json
  3. Copy the root .editorconfig to the template (or run .\CopyEditorConfigToTemplates.ps1)
  4. Ensure template CI includes strict dotnet format checks (whitespace, style, analyzers)
  5. Update CI reusable workflow inputs/matrix JSON (in build.yml and .github/workflows/template-validation.yml)
  6. Update this README with the new template

EditorConfig management

Templates include .editorconfig files based on the root .editorconfig for consistent defaults.

CI enforces formatting via strict checks:

  • dotnet format whitespace <target> --verify-no-changes --no-restore
  • dotnet format style <target> --verify-no-changes --no-restore --severity info
  • dotnet format analyzers <target> --verify-no-changes --no-restore --severity info

CI architecture is intentionally DRY and schema-driven:

  • build.yml orchestrates package build, dynamic matrix generation, and top-level test gates
  • .github/scripts/Get-TemplateCiMatrix.ps1 discovers template options from template.json, validates against the template schema, and emits workflow matrices
  • .github/workflows/template-validation.yml is the reusable workflow for standard template validation variants
  • .github/actions/setup-template-test and .github/actions/trx-playlist provide reusable native GitHub Actions setup and test-result handling

For template-specific customizations:

  • Keep template-specific rules in templates/<Template>/.template.config/editorconfig.override
  • Override files are authoring metadata only; generated projects still contain a single final .editorconfig
  • The NuGet template uses this pattern for its relaxed style severity and namespace preferences

When updating root .editorconfig:

Automated Process (Recommended):

  • Simply update the root .editorconfig file and push to main
  • The update-template-editorconfig GitHub Actions workflow will automatically:
    • Detect root or override changes and run the copy script
    • Create or update a PR with the template updates
    • Compose each template .editorconfig from root baseline + optional override
    • Provide clear documentation of what was changed

Manual Process:

  1. Update the root .editorconfig file
  2. If a template needs custom rules, edit .template.config/editorconfig.override for that template
  3. Run ./CopyEditorConfigToTemplates.ps1 (rerun this script after any override edits)
  4. Test all templates to ensure they work correctly

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors