GitInfo 2.2.0

Install-Package GitInfo -Version 2.2.0
dotnet add package GitInfo --version 2.2.0
<PackageReference Include="GitInfo" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GitInfo --version 2.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: GitInfo, 2.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install GitInfo as a Cake Addin
#addin nuget:?package=GitInfo&version=2.2.0

// Install GitInfo as a Cake Tool
#tool nuget:?package=GitInfo&version=2.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Icon GitInfo

Git 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.

Build status Latest version Downloads License

Usage

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 Git static class:

Console.WriteLine(ThisAssembly.Git.Commit);

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

open System.Reflection

[<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)>]

do ()

VB:

<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)>

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.

Details

Exposes the following information for use directly from any MSBuild target that depends on the GitInfo target:

  $(GitRepositoryUrl)
  $(GitBranch)
  $(GitCommit)
  $(GitCommitDate)
  $(GitCommits)
  $(GitTag)
  $(GitBaseTag)
  $(GitBaseVersionMajor)
  $(GitBaseVersionMinor)
  $(GitBaseVersionPatch)
  $(GitSemVerMajor)
  $(GitSemVerMinor)
  $(GitSemVerPatch)
  $(GitSemVerLabel)
  $(GitSemVerDashLabel)
  $(GitSemVerSource)
  $(GitIsDirty)

From C#, F# and VB, by default code is generated too so that the same information can be accessed from code, to construct your own assembly/file version attributes with whatever format you want:

[assembly: AssemblyVersion (ThisAssembly.Git.SemVer.Major + "." + ThisAssembly.Git.SemVer.Minor + "." + ThisAssembly.Git.SemVer.Patch)]
[assembly: AssemblyInformationalVersion (
  ThisAssembly.Git.SemVer.Major + "." +
  ThisAssembly.Git.SemVer.Minor + "." +
  ThisAssembly.Git.SemVer.Patch + "-" +
  ThisAssembly.Git.Branch + "+" +
  ThisAssembly.Git.Commit)]
// i..e ^: 1.0.2-main+c218617

NOTE: you may need to close and reopen the solution in order for Visual Studio to refresh intellisense and show the ThisAssembly type right after package installation for the first time.

All generated constants also have a Summary documentation tag that shows the current value in the intellisense tooltip, making it very easy to see what the different values contain.

The available constants from code are:

  ThisAssembly.Git.RepositoryUrl
  ThisAssembly.Git.Branch
  ThisAssembly.Git.Commit
  ThisAssembly.Git.Commits
  ThisAssembly.Git.Tag
  ThisAssembly.Git.BaseTag
  ThisAssembly.Git.BaseVersion.Major
  ThisAssembly.Git.BaseVersion.Minor
  ThisAssembly.Git.BaseVersion.Patch
  ThisAssembly.Git.SemVer.Major
  ThisAssembly.Git.SemVer.Minor
  ThisAssembly.Git.SemVer.Patch
  ThisAssembly.Git.SemVer.Label
  ThisAssembly.Git.SemVer.DashLabel
  ThisAssembly.Git.SemVer.Source
  ThisAssembly.Git.IsDirty

Available MSBuild customizations:

  $(GitThisAssembly): set to 'false' to prevent assembly 
                      metadata and constants generation.

  $(GitThisAssemblyMetadata): set to 'false' to prevent assembly 
                              metadata generation only. Defaults 
                              to 'false'.

  $(ThisAssemblyNamespace): allows overriding the namespace
                            for the ThisAssembly class.
                            Defaults to the global namespace.

  $(GitRemote): name of remote to get repository url for.
                Defaults to 'origin'.

  $(GitDefaultBranch): determines the base branch used to 
                       calculate commits on top of current branch.
                       Defaults to 'master'.

  $(GitVersionFile): determines the name of a file in the Git 
                     repository root used to provide the base 
                     version info.
                     Defaults to 'GitInfo.txt'.

  $(GitInfoReportImportance): allows rendering all the retrieved
                              git information with the specified
                              message importance ('high', 
                              'normal' or 'low').
                              Defaults to 'low'.

  $(GitIgnoreBranchVersion) and $(GitIgnoreTagVersion): determines 
                            whether the branch and tags (if any) 
                            will be used to find a base version.
                            Defaults to empty value (no ignoring).

  $(GitSkipCache): whether to cache the Git information determined
           in a previous build in a GitInfo.cache for
           performance reasons.
           Defaults to empty value (no ignoring).

  $(GitNameRevOptions): Options passed to git name-rev when finding
              a branch name for the current commit (Detached head). The default is
              '--refs=refs/heads/* --no-undefined --alwas'
              meaning branch names only, falling back to commit hash.
              For legacy behavior where $(GitBranch) for detached head
              can also be a tag name, use '--refs=refs/*'.
              Refs can be included and excluded, see git name-rev docs.

  $(GitTagRegex): Regular expression used with git describe to filter the tags 
                  to consider for base version lookup.
                  Defaults to * (all)
           
  $(GitBaseVersionRegex): Regular expression used to match and validate valid base versions
                          in branch, tag or file sources. By default, matches any string that 
                          *ends* in a valid SemVer2 string.
                          Defaults to 'v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)(?:\-(?<LABEL>[\dA-Za-z\-\.]+))?$|^(?<LABEL>[\dA-Za-z\-\.]+)\-v?(?<MAJOR>\d+)\.(?<MINOR>\d+)\.(?<PATCH>\d+)$'

Goals

  • No compiled code or tools → 100% transparency
  • Trivially added/installed via a NuGet package
  • No format strings or settings to learn
  • Single well-structured .targets file with plain MSBuild and no custom tasks
  • Optional embedding of Git info in assembly as metadata
  • Optional use of Git info to build arbitrary assembly/file version information, both in C# as well as VB.
  • Trivially modified/improved generated code by just adjusting a C# or F# or VB template included in the NuGet package
  • Easily modified/improved by just adjusting a single .targets file
  • 100% incremental build-friendly and high-performing (all proper Inputs/Outputs in place, smart caching of Git info, etc.)

Sponsors

sponsored clariusclarius

get mentioned here too!

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on GitInfo:

Package Downloads
Aqovia.PactProducerVerifier.AspNetCore

Pact Producer Test for aspnet core sites

Zooqle.Net

A .NET Standard library for searching torrents on Zooqle.

BizStream.NET.Sdk

Core build and release configuration for packages and libraries distributed by BizStream.

Xamarin.VisualStudio.AndroidX.Migration The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

This package provides a Roslyn based migrator to be used in Visual Studio and Visual Studio for Mac.

SPLogging.Web

Web Log helper ใช้สำหรับ ช่วยเก็บค่า sesion และ อื่นๆ สำหรับ log

GitHub repositories (17)

Showing the top 5 popular GitHub repositories that depend on GitInfo:

Repository Stars
dotnet/maui
.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
veler/DevToys
A Swiss Army knife for developers.
gitextensions/gitextensions
Git Extensions is a standalone UI tool for managing git repositories. It also integrates with Windows Explorer and Microsoft Visual Studio (2015/2017/2019).
xamarin/Xamarin.Forms
Xamarin.Forms Official Home
moq/moq4
Repo for managing Moq 4.x
Version Downloads Last updated
2.2.0 416,612 8/26/2021
2.1.2 602,817 9/24/2020
2.1.1 489 9/24/2020
2.0.40 1,097 9/24/2020
2.0.39 1,568 9/23/2020
2.0.38 1,121 9/21/2020
2.0.37 771 9/20/2020
2.0.36 418 9/20/2020
2.0.35 418 9/20/2020
2.0.34 6,075 9/11/2020
2.0.33 9,485 8/28/2020
2.0.32 353 8/28/2020
2.0.31 59,724 8/3/2020
2.0.30 11,045 7/27/2020
2.0.29 7,960 7/22/2020
2.0.28 363 7/22/2020
2.0.27 351 7/22/2020
2.0.26 343,011 12/16/2019
2.0.25 1,315 12/13/2019
2.0.21 82,144 10/15/2019
2.0.20 529,263 11/13/2018
2.0.19 9,858 11/2/2018
2.0.18 95,961 9/26/2018
2.0.17 17,804 9/10/2018
2.0.16 708 9/10/2018
2.0.15 25,337 8/14/2018
2.0.14 1,885 8/3/2018
2.0.11 333,403 6/1/2018
2.0.10 32,206 2/21/2018
2.0.9 1,050 2/20/2018
2.0.8 12,878 11/30/2017
2.0.7 6,968 11/30/2017
2.0.6 16,598 10/22/2017
2.0.5 798 10/19/2017
2.0.3 8,005 10/18/2017
2.0.2 2,844 9/29/2017
2.0.1 87,962 8/24/2017
2.0.0 3,335 8/16/2017
1.1.72 1,684 8/7/2017
1.1.71 5,270 7/10/2017
1.1.70 769 7/10/2017
1.1.68 964 7/7/2017
1.1.67 1,065 7/4/2017
1.1.66 1,210 6/23/2017
1.1.65 1,089 6/15/2017
1.1.63 1,014 6/15/2017
1.1.62 2,230 6/4/2017
1.1.61 4,177 5/31/2017
1.1.60 1,569 5/16/2017
1.1.59 15,701 5/11/2017
1.1.58 1,099 5/5/2017
1.1.57 944 4/29/2017
1.1.56 818 4/28/2017
1.1.55 1,130 4/26/2017
1.1.54 786 4/26/2017
1.1.53 1,513 4/12/2017
1.1.48 2,945 2/10/2017
1.1.47 799 2/10/2017
1.1.45 2,401 1/27/2017
1.1.44 795 1/27/2017
1.1.43 876 1/25/2017
1.1.41 819 1/25/2017
1.1.40 1,154 1/6/2017
1.1.39 1,133 12/26/2016
1.1.38 1,576 12/26/2016
1.1.37 1,082 12/12/2016
1.1.35 1,740 11/29/2016
1.1.34 1,098 11/24/2016
1.1.31 1,520 9/13/2016
1.1.30 875 9/13/2016
1.1.29 1,446 9/3/2016
1.1.28 1,710 8/10/2016
1.1.27 943 8/8/2016
1.1.26 840 8/8/2016
1.1.25 2,414 7/28/2016
1.1.24 1,097 7/28/2016
1.1.23 1,080 7/28/2016
1.1.22 1,160 7/28/2016
1.1.20 1,761 6/4/2016
1.1.19 936 5/29/2016
1.1.17 869 5/26/2016
1.1.15 2,839 5/23/2016
1.1.14 2,009 5/22/2016
1.1.13 926 5/19/2016
1.1.12 3,014 4/24/2016
1.1.10 1,015 4/8/2016
1.1.9 902 3/31/2016
1.1.8 864 3/31/2016
1.1.7 835 3/31/2016
1.1.5 1,383 3/16/2016
1.1.4 859 3/16/2016
1.1.2 917 3/14/2016
1.1.1 1,463 3/12/2016
1.1.0 950 3/11/2016
1.0.64-pre 746 3/12/2016
1.0.63-pre 761 3/12/2016
1.0.62-pre 853 3/12/2016
1.0.61-pre 892 3/12/2016
1.0.60-pre 759 3/11/2016
1.0.59-pre 849 3/11/2016
1.0.58-pre 780 3/11/2016
1.0.56-pre 3,029 1/9/2016
1.0.55-pre 1,658 1/7/2016
1.0.54-pre 1,303 12/14/2015
1.0.53-pre 869 12/10/2015
1.0.52-pre 1,081 12/10/2015
1.0.51-pre 874 12/10/2015
1.0.50-pre 881 12/9/2015
1.0.49-pre 2,560 10/5/2015
1.0.48-pre 1,091 10/3/2015
1.0.47-pre 936 9/2/2015
1.0.46-pre 811 9/2/2015
1.0.45-pre 849 9/1/2015
1.0.44-pre 821 9/1/2015
1.0.43-pre 805 9/1/2015
1.0.42-pre 824 8/18/2015
1.0.41-pre 1,109 8/7/2015
1.0.40-pre 836 7/19/2015
1.0.39-pre 818 7/10/2015
1.0.38-pre 817 6/26/2015
1.0.37-pre 791 6/26/2015
1.0.36-pre 779 6/26/2015
1.0.35-pre 798 6/26/2015
1.0.34-pre 798 6/24/2015
1.0.33-pre 888 6/17/2015
1.0.31-pre 830 6/16/2015
1.0.30-pre 788 6/16/2015
1.0.29-pre 785 6/16/2015
1.0.28-pre 783 6/16/2015
1.0.27-pre 793 6/16/2015
1.0.26-pre 830 6/15/2015
1.0.25-pre 815 6/14/2015
1.0.24-pre 817 6/11/2015
1.0.23-pre 800 6/8/2015
1.0.22-pre 803 6/8/2015
1.0.21-pre 787 6/8/2015
1.0.20-pre 825 6/8/2015
1.0.19-pre 792 6/8/2015
1.0.18-pre 802 6/8/2015
1.0.16-pre 801 6/5/2015
1.0.15-pre 833 6/5/2015
1.0.14-pre 863 6/4/2015
1.0.11-pre 804 6/3/2015
1.0.10-pre 822 6/3/2015
1.0.9-pre 829 6/3/2015
1.0.8-pre 817 6/3/2015
1.0.7-pre 867 6/3/2015
1.0.6-pre 795 6/3/2015
1.0.5-pre 811 6/3/2015
1.0.4-pre 805 6/3/2015
1.0.3-pre 798 6/3/2015
1.0.1-pre 802 6/3/2015
1.0.0 1,072 2/22/2016
1.0.0-pre 796 5/26/2015
0.0.196 335 10/14/2020
0.0.195 334 10/5/2020
0.0.194 678 9/24/2020