Sharing code between microservices should be easy.
In the beginning, we made the classic mistake: copy-pasting the Contracts project between solutions. “It’s just one file,” we said. “It won’t change often,” we said.
Narrator: It changed often.
Then we grew up and started building NuGet packages. But manually packing and uploading to an internal feed is a drag. You forget to bump the version. You upload a debug build by mistake. It’s DLL Hell reinvented.
Automated Factory
For our public-facing Contracts library in MyProject, we decided to automate the entire lifecycle using GitHub Actions.
The goal:
- Developer modifies a contract.
- Developer pushes to
main. - GitHub Actions builds, packs, and pushes a new version to NuGet.org.
- I drink coffee.
The Workflow
Here is the secret sauce. We use a GitHub Action that triggers only when files in the specific project folder change.
| |
Configuring Versioning
This workflow is great, but how do we handle version numbers? We found that simply updating the <Version> tag in the .csproj file before merging is the simplest way for now. The pipeline does the rest.
Now, our consuming apps can just run dotnet add package MyProject.Contracts and always get the latest definitions without me having to lift a finger.
