Templated repos with dotnet new

1 minute read (204 words)

I’ve been digging in to making dotnet new templates and it turns out to be a remarkably capable bit of tooling.

It’s particularly useful when you want to build a load of similar microservices with their own git repos.

It can:

  • Rename files.
  • Rename strings (variables, class names etc).
  • Preserve case style of renamed strings (through “derived” replacements).
  • Create named command line arguments for your template string replacements, e.g. donet new mytemplate --myswitch MyReplacementValue.
  • Exclude entire blocks of code and files based on switches that user can provide.
  • Be installed an tested from a local folder with dotnet new install <path>.
  • Be built into a nuget package and published on private or public feeds.

Importantly, there’s nothing in the way that it works that stops you from making your template code build/test/run.

And because it’s a CLI tool, if you want to an update an existing generated repo with a new version of a template you can just run it again with --force, and use git to pick through what changes you want to take into the generated repo.

This really takes a lot of the toil out of the copy-paste-modify you would have to do otherwise.

Learn more:

See also:


Discuss on Reddit || Tweet This || Post to LinkedIn || Page Source

Subscribe for updates on software development, contracting, side projects, blog posts and who knows what else. Read the archives for an idea of content.

Mailing list powered by the excellent buttondown.email.