Skip to content

Add an optional BenchmarkDotNet project to the templates - #138

Merged
dennisdoomen merged 2 commits into
mainfrom
claude/issue-118-6d0f31
Sep 26, 2026
Merged

dennisdoomen merged 2 commits into
mainfrom
claude/issue-118-6d0f31

Conversation

@dennisdoomen

Copy link
Copy Markdown
Owner

Closes #118

What changed

All six templates now have a --benchmarks option (default: false):

dotnet new oss-nuget-class-library-sln --name MyLib --benchmarks true

When it is on, the generated solution gets:

  • A MyPackage.Benchmarks project (net10.0, BenchmarkDotNet 0.15.8) with one example benchmark (string.Join vs StringBuilder). The example does not use MyClass, because in source-only packages that class is not visible to other assemblies.
  • A .editorconfig for that project. BenchmarkDotNet needs public, non-sealed classes and instance methods, which the analyzers would otherwise report as errors.
  • A RunBenchmarks build target. It is never part of Default, because benchmarks are slow and their results are not reliable on shared CI agents. It always runs in Release, takes a --benchmark-filter parameter (default *) and writes results to Artifacts/Benchmarks.
  • A tip in the generated README.

How it works

  • template.json has a new benchmarks bool symbol. When it is false, a source modifier leaves out the MyPackage.Benchmarks folder.
  • SpecialCustomOperations turn on <!--#if (benchmarks) --> blocks in .slnx and .md files.
  • In Build.cs the target is wrapped in //#if (benchmarks) instead of #if. This way the code still compiles when this repo's own TestTemplateBuild builds the rendered templates.
  • The root TestPackageInstallation target now also builds both OSS templates with --benchmarks true. I added :nq so Fallout does not put quotes around the template name plus options.

Testing

  • TestPackageInstallation passes for all six variants, including both --benchmarks true runs.
  • A full build.ps1 Pack on the rendered Normal template passes: InspectCode, tests, PackageGuard (BenchmarkDotNet's dependencies pass the license check) and API checks.
  • build.ps1 RunBenchmarks on a generated solution produced the markdown, CSV and HTML reports.

Notes for reviewers

  • Storing baselines to compare results across runs is out of scope, as the issue says.
  • With BenchmarkDotNet's default job, the example benchmark takes about 8.5 minutes to run.

🤖 Generated with Claude Code

dennisdoomen and others added 2 commits September 26, 2026 10:45
Adds a --benchmarks template option that generates a MyPackage.Benchmarks
project with an example benchmark and a RunBenchmarks build target. The
target is never part of Default, because benchmarks are slow and their
results are not reliable on shared CI agents.

Closes #118

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves conflicts with the new Dependabot/Renovate option: the benchmarks
modifier and symbol apply to all templates, the dependency updater ones only
to the GitHub templates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dennisdoomen dennisdoomen added the enhancement New feature or request label Sep 26, 2026
@dennisdoomen
dennisdoomen merged commit 2fd17a3 into main Sep 26, 2026
1 check passed
@dennisdoomen
dennisdoomen deleted the claude/issue-118-6d0f31 branch September 26, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add an optional BenchmarkDotNet project to the templates

1 participant