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!

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay