Git and SemVer Info from MSBuild, C# and VB
A fresh and transparent approach to Git information retrieval from MSBuild and Code without using any custom tasks or compiled code and tools, obscure settings, format strings, etc.
After installing via NuGet:
PM> Install-Package GitInfo
By default, if the containing project is a C#, F# or VB project, a compile-time generated source file will contain all the git information and can be accessed from anywhere within the assembly, as constants in a
ThisAssembly(partial) class and its nested
All generated constants also have a Summary documentation tag that shows the current value in the intellisense tooltip, making it easier to see what the different values contain:
NOTE: you may need to close and reopen the solution in order for Visual Studio to refresh intellisense and show the ThisAssembly type the first time after installing the package.
With this information at your fingertips, you can build any versioning attributes you want, with whatever information you want, without resorting to settings, format strings or anything, just plain code:
C#: ``` [assembly: AssemblyVersion (ThisAssembly.Git.BaseVersion.Major + "." + ThisAssembly.Git.BaseVersion.Minor + "." + ThisAssembly.Git.BaseVersion.Patch)]
[assembly: AssemblyFileVersion (ThisAssembly.Git.SemVer.Major + "." + ThisAssembly.Git.SemVer.Minor + "." + ThisAssembly.Git.SemVer.Patch)]
[assembly: AssemblyInformationalVersion ( ThisAssembly.Git.SemVer.Major + "." + ThisAssembly.Git.SemVer.Minor + "." + ThisAssembly.Git.Commits + "-" + ThisAssembly.Git.Branch + "+" + ThisAssembly.Git.Commit)] ```
F#: ``` module AssemblyInfo
do () ```
Because this information is readily available whenever you build the project, you never depend on CI build scripts that generate versions for you, and you can always compile locally exactly the same version of an assembly that was built by a CI server.
You can read more about this project at the GitInfo announcement blog post.