.NET solution templates for class library packages
About this new project
I like to build my software systems in a nicely broken down set of libraries that are easy to maintain, test and deploy based on the Principles Of Successful Package Management. But every time I or the teams I work with need to start a new library or reusable component, we have to scramble so much from other projects, I felt this good fill the gap.
So I’ve started to create a bunch of dotnet new
templates to quickly get you started building high-quality libraries including everything you need to publish it on NuGet or make it available as open-source.
It includes:
- Multi-targeting to cover as many .NET frameworks as possible
- Code coverage using Coverlet and Coveralls.io
- Static code analysis using Roslyn analyzers StyleCopAnalyzers, Roslynator, CSharpGuidelinesAnalyzer and Meziantou.
- Auto-formatting using
.editorconfig
and settings honored by JetBrains Rider and ReSharper - A Nuke C# build script that you can run locally as well as in your CI/CD pipeline
- A GitHub Actions workflow that builds, tests, packages and publishes your library
- An extensive read-me
- Automatic versioning using GitVersion and tagging
- Contribution guidelines
- Customized release notes templates for GitHub connected to pull requests labels.
- A test project using xUnit and Fluent Assertions 7
- Validation of the public API of the library against snapshots using Verify
This is the result of years of experience in building in-house and open-source libraries that are used by thousands of developers around the world. I hope it’s a great starting point for building your own libraries.
You can also use this as a starting point for a GitHub Template Repository, fork and adapt the repository for your own company, or use it as an organization template in Azure DevOps.
How to get started
Everything is documented at the repository, but here’s a summary of the approach:
- Create a new directory for your library initialized with Git
- Run
dotnet new class-library-package-solution -name TheNameOfYourAwesomeLibrary
- Make the necessary changes to the generated code
- Commit the changes to your repository into a new commit
- Run
build.ps1
to build the code, run the tests, and package the library into a NuGet package in theArtifacts
directory. - Use a Github Actions workflow to push to NuGet
Stuff you can customize includes
- Update the
README.md
with information about your library - Review the guidelines in
CONTRIBUTION.md
to see if it aligns with how you want to handle contributions - Adjust the .NET frameworks this library should target
- Adjust the namespace
- Set-up labels in GitHub matching those in the
release.yml
so you can label pull requests accordingly - Alter the coverage service that is being used.
- Determine if you want to use API verification against snapshots
- Study the Nuke
build.cs
file or invoking it throughbuild.ps1 -plan
to see how it works - See if all dependencies are up-to-date
- Adjust the
funding.yml
to allow people to sponsor your project
About me
I’m a Microsoft MVP and Principal Consultant at Aviva Solutions with 28 years of experience under my belt. As a coding software architect and/or lead developer, I specialize in building or improving (legacy) full-stack enterprise solutions based on .NET as well as providing coaching on all aspects of designing, building, deploying and maintaining software systems. I’m the author of Fluent Assertions, a popular .NET assertion library, Liquid Projections, a set of libraries for building Event Sourcing projections and I’ve been maintaining coding guidelines for C# since 2001. You can find me on Twitter, Mastadon and Blue Sky.
Leave a Comment