GitInfo 3.3.5

dotnet add package GitInfo --version 3.3.5
NuGet\Install-Package GitInfo -Version 3.3.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GitInfo" Version="3.3.5">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GitInfo --version 3.3.5
#r "nuget: GitInfo, 3.3.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. 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=3.3.5

// Install GitInfo as a Cake Tool
#tool nuget:?package=GitInfo&version=3.3.5

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.

Latest version Downloads License Build status

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

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.

By default, GitInfo will also set $(Version) and $(PackageVersion) which the .NET SDK uses for deriving the AssemblyInfo, FileVersion and InformationalVersion values, as well as for packing. This default version is formatted from the following populated MSBuild properties: $(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)+$(GitBranch).$(GitCommit).

So, straight after install and build/pack, you will get some versioning in place 😃.

Alternatively, you can opt-out of this default versioning by setting GitVersion=false in your project file, if you want to just leverage the Git information and/or version properties/constants yourself:

<PropertyGroup>
    <GitVersion>false</GitVersion>
</PropertyGroup>

This allows you to use the provided constants to 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)>

NOTE: when generating your own assembly version attributes, you will need to turn off the corresponding assembly version attribute generation from the .NET SDK, by setting the relevant properties to false: GenerateAssemblyVersionAttribute, GenerateAssemblyFileVersionAttribute and GenerateAssemblyInformationalVersionAttribute.

MSBuild:

  
<PropertyGroup>
    
    <GitVersion>false</GitVersion>
</PropertyGroup>
<ItemGroup>
  <PackageReference Include="GitInfo" PrivateAssets="all" />
</ItemGroup>

<Target Name="PopulateInfo" DependsOnTargets="GitVersion" BeforeTargets="GetAssemblyVersion;GenerateNuspec;GetPackageContents">
    <PropertyGroup>
      <Version>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)+$(GitBranch).$(GitCommit)</Version>
      <PackageVersion>$(Version)</PackageVersion>
      
      <RepositoryBranch>$(GitBranch)</RepositoryBranch>
      <RepositoryCommit>$(GitCommit)</RepositoryCommit>
      <SourceRevisionId>$(GitBranch) $(GitCommit)</SourceRevisionId>
    </PropertyGroup>
</Target>

NOTE: because the provided properties are populated via targets that need to run before they are available, you cannot use the GitInfo-provided properties in a PropertyGroup at the project level. You can only use them from within a target that in turn depends on the relevant target from GitInfo (typically, GitVersion as shown above, if you consume the SemVer properties).

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)

For C#, F# and VB, constants are generated too so that the same information can be accessed from code:

  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 properties to customize the behavior:

  $(GitVersion): set to 'false' to prevent setting Version 
                 and PackageVersion.

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

  $(GitThisAssemblyMetadata): set to 'false' to prevent assembly 
                              metadata generation only. Defaults 
                              to 'false'. If 'true', it will also 
                              provide assembly metadata attributes 
                              for each of the populated values.

  $(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 'main'.

  $(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).

  $(GitCachePath): where to cache the determined Git information
				   gives the chance to use a shared location
				   for different projects. this can improve
				   the overall build time.
				   has to end with a path seperator
				   Defaults to empty value ('$(IntermediateOutputPath)').

  $(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 --always'
              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
  • Simple well-structured .targets file with plain MSBuild and no custom tasks
  • Optional embedding of Git info in assembly 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
  • 100% incremental build-friendly and high-performing (all proper Inputs/Outputs in place, smart caching of Git info, etc.)

Sponsors

Clarius Org Kirill Osenkov MFB Technologies, Inc. Stephen Shaw Torutek DRIVE.NET, Inc. Ashley Medway Keith Pickford Thomas Bolon Kori Francis Toni Wenzel Giorgi Dalakishvili Mike James Uno Platform Dan Siegel Reuben Swartz Jacob Foshee alternate text is missing from this package README image Eric Johnson Certify The Web Ix Technologies B.V. David JENNI Jonathan Oleg Kyrylchuk Charley Wu Jakob Tikjøb Andersen Seann Alexander Tino Hager Mark Seemann Angelo Belchior Ken Bonny Simon Cropp agileworks-eu sorahex Zheyu Shen Vezel Michael Staib ChilliCream 4OTC

Sponsor this project  

Learn more about GitHub Sponsors

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages (11)

Showing the top 5 NuGet packages that depend on GitInfo:

Package Downloads
Aqovia.PactProducerVerifier.AspNetCore

Pact Producer Test for aspnet core sites

PH.RollingZipRotatorLog4net

A netstandard2.0 Zip utility to perform a very simple log4net file rotation. The code perform a zip-compression on every log-rotated file and delete it, watching on log4net output directory reading settings of appenders.

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.

SPLogging.Web

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

GitHub repositories (37)

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

Repository Stars
DevToys-app/DevToys
A Swiss Army knife for developers.
dotnet/maui
.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
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 is no longer supported. Migrate your apps to .NET MAUI.
EventStore/EventStore
EventStoreDB, the event-native database. Designed for Event Sourcing, Event-Driven, and Microservices architectures
Version Downloads Last updated
3.3.5 3,164 5/13/2024
3.3.4 43,112 2/15/2024
3.3.3 249,619 8/30/2023
3.3.2 358 8/30/2023
3.3.1 15,153 8/11/2023
3.3.0 590 8/11/2023
3.2.0 4,218 8/11/2023
2.3.0 555,246 11/18/2022
2.2.1 9,414 11/16/2022
2.2.0 1,335,602 8/26/2021
2.1.2 1,046,621 9/24/2020
2.1.1 804 9/24/2020
2.0.40 2,035 9/24/2020
2.0.39 3,050 9/23/2020
2.0.38 1,461 9/21/2020
2.0.37 1,075 9/20/2020
2.0.36 731 9/20/2020
2.0.35 721 9/20/2020
2.0.34 8,195 9/11/2020
2.0.33 11,096 8/28/2020
2.0.32 679 8/28/2020
2.0.31 66,159 8/3/2020
2.0.30 14,723 7/27/2020
2.0.29 45,798 7/22/2020
2.0.28 699 7/22/2020
2.0.27 704 7/22/2020
2.0.26 434,883 12/16/2019
2.0.25 1,649 12/13/2019
2.0.21 89,684 10/15/2019
2.0.20 636,858 11/13/2018
2.0.19 11,553 11/2/2018
2.0.18 102,755 9/26/2018
2.0.17 20,774 9/10/2018
2.0.16 1,011 9/10/2018
2.0.15 55,102 8/14/2018
2.0.14 2,508 8/3/2018
2.0.11 340,132 6/1/2018
2.0.10 33,209 2/21/2018
2.0.9 1,415 2/20/2018
2.0.8 15,213 11/30/2017
2.0.7 7,376 11/30/2017
2.0.6 18,420 10/22/2017
2.0.5 1,133 10/19/2017
2.0.3 8,447 10/18/2017
2.0.2 3,230 9/29/2017
2.0.1 88,963 8/24/2017
2.0.0 3,846 8/16/2017
1.1.72 2,112 8/7/2017
1.1.71 6,215 7/10/2017
1.1.70 1,108 7/10/2017
1.1.68 1,289 7/7/2017
1.1.67 1,407 7/4/2017
1.1.66 1,526 6/23/2017
1.1.65 1,412 6/15/2017
1.1.63 1,444 6/15/2017
1.1.62 2,576 6/4/2017
1.1.61 4,555 5/31/2017
1.1.60 1,931 5/16/2017
1.1.59 16,068 5/11/2017
1.1.58 1,406 5/5/2017
1.1.57 1,305 4/29/2017
1.1.56 1,131 4/28/2017
1.1.55 5,430 4/26/2017
1.1.54 1,138 4/26/2017
1.1.53 1,935 4/12/2017
1.1.48 3,461 2/10/2017
1.1.47 1,091 2/10/2017
1.1.45 2,743 1/27/2017
1.1.44 1,102 1/27/2017
1.1.43 1,196 1/25/2017
1.1.41 1,143 1/25/2017
1.1.40 1,505 1/6/2017
1.1.39 1,448 12/26/2016
1.1.38 1,920 12/26/2016
1.1.37 1,394 12/12/2016
1.1.35 2,145 11/29/2016
1.1.34 1,480 11/24/2016
1.1.31 1,872 9/13/2016
1.1.30 1,186 9/13/2016
1.1.29 1,819 9/3/2016
1.1.28 2,246 8/10/2016
1.1.27 1,259 8/8/2016
1.1.26 1,151 8/8/2016
1.1.25 2,776 7/28/2016
1.1.24 1,423 7/28/2016
1.1.23 1,432 7/28/2016
1.1.22 1,517 7/28/2016
1.1.20 2,194 6/4/2016
1.1.19 1,277 5/29/2016
1.1.17 1,183 5/26/2016
1.1.15 3,163 5/23/2016
1.1.14 2,364 5/22/2016
1.1.13 1,272 5/19/2016
1.1.12 3,333 4/24/2016
1.1.10 1,371 4/8/2016
1.1.9 1,227 3/31/2016
1.1.8 1,176 3/31/2016
1.1.7 1,176 3/31/2016
1.1.5 1,716 3/16/2016
1.1.4 1,187 3/16/2016
1.1.2 1,231 3/14/2016
1.1.1 1,812 3/12/2016
1.1.0 1,287 3/11/2016
1.0.64-pre 881 3/12/2016
1.0.63-pre 935 3/12/2016
1.0.62-pre 1,036 3/12/2016
1.0.61-pre 1,041 3/12/2016
1.0.60-pre 918 3/11/2016
1.0.59-pre 1,037 3/11/2016
1.0.58-pre 910 3/11/2016
1.0.56-pre 3,178 1/9/2016
1.0.55-pre 1,810 1/7/2016
1.0.54-pre 1,544 12/14/2015
1.0.53-pre 1,044 12/10/2015
1.0.52-pre 1,269 12/10/2015
1.0.51-pre 1,038 12/10/2015
1.0.50-pre 1,076 12/9/2015
1.0.49-pre 2,749 10/5/2015
1.0.48-pre 1,269 10/3/2015
1.0.47-pre 1,111 9/2/2015
1.0.46-pre 962 9/2/2015
1.0.45-pre 1,017 9/1/2015
1.0.44-pre 979 9/1/2015
1.0.43-pre 973 9/1/2015
1.0.42-pre 983 8/18/2015
1.0.41-pre 1,302 8/7/2015
1.0.40-pre 1,017 7/19/2015
1.0.39-pre 971 7/10/2015
1.0.38-pre 986 6/26/2015
1.0.37-pre 937 6/26/2015
1.0.36-pre 952 6/26/2015
1.0.35-pre 970 6/26/2015
1.0.34-pre 984 6/24/2015
1.0.33-pre 1,040 6/17/2015
1.0.31-pre 1,005 6/16/2015
1.0.30-pre 965 6/16/2015
1.0.29-pre 953 6/16/2015
1.0.28-pre 962 6/16/2015
1.0.27-pre 974 6/16/2015
1.0.26-pre 1,002 6/15/2015
1.0.25-pre 982 6/14/2015
1.0.24-pre 1,011 6/11/2015
1.0.23-pre 962 6/8/2015
1.0.22-pre 965 6/8/2015
1.0.21-pre 973 6/8/2015
1.0.20-pre 997 6/8/2015
1.0.19-pre 967 6/8/2015
1.0.18-pre 975 6/8/2015
1.0.16-pre 977 6/5/2015
1.0.15-pre 1,003 6/5/2015
1.0.14-pre 1,034 6/4/2015
1.0.11-pre 941 6/3/2015
1.0.10-pre 988 6/3/2015
1.0.9-pre 995 6/3/2015
1.0.8-pre 966 6/3/2015
1.0.7-pre 1,028 6/3/2015
1.0.6-pre 953 6/3/2015
1.0.5-pre 944 6/3/2015
1.0.4-pre 984 6/3/2015
1.0.3-pre 962 6/3/2015
1.0.1-pre 981 6/3/2015
1.0.0 1,426 2/22/2016
1.0.0-pre 951 5/26/2015
0.0.196 602 10/14/2020
0.0.195 614 10/5/2020
0.0.194 2,170 9/24/2020