Modelon Solutions

A fresh take on your ideas

Git, Roslyn and Nuget Magic

Published by

on

I was writing some code into To-Do.Studio so that when people demo their code and features, I have a better idea of what it is I am seeing – more specifically, what version number would I see (to understand branches and commits)…

My initial thought was : on startup i will launch git and try to get some information about branch and commit hash and then incorporate that into the configuration system and then show that in the footer…

Well, that sounded complicated and so it probably was… after a few seconds, I found this great Nuget called GitInfo that basically creates a partial class at build time that can be referred to in code,  my startup code now looks like this :

public string GitVersion
{
    get => string.Format($"V{ThisAssembly.Git.BaseVersion.Major}.{ThisAssembly.Git.BaseVersion.Minor}.{ThisAssembly.Git.BaseVersion.Patch} T={ThisAssembly.Git.Tag} {ThisAssembly.Git.Branch}[{ThisAssembly.Git.Commit}] {{0}}", ThisAssembly.Git.IsDirty?"Dirty":"");
}
...
Configure()
{
    ...
    Configuration["GitVersion"] = GitVersion;
    ...
}

Leave a comment

Create a website or blog at WordPress.com