DEV Community

Jim Borden
Jim Borden

Posted on

2 1

Git commit info in your build

For quite a long time I've been generating git commit info for use inside my assemblies at work but I've been doing it in a roundabout fragile way. I found a library that includes an MSBuild task to do it for me called GitInfo. I was skeptical at first but it was literally the easiest thing I could possibly do.

All you need to do to use it is add the Nuget package. Behind the scenes what it does is generate a new target for MSBuild to run which adds another autogenerated file based on a template. It's nothing too fancy, but it takes care of a lot of annoying things for you like trying to locate the git executable and running various git commands to extract useful information. Auto generated files are like the ones that get automatically generated when you have XAML files in your project (*.g.cs). They wind up in your "output" directory and don't interfere with your git staging area. But because it is compiled source, all you need to do is call into a static class to get all the juicy git info. Personally, I use ThisAssembly.Git.Commit which is the short commit hash. However, there is a whole lot more to play with.

Check it out!

Billboard image

Monitoring as code

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay