GitInfo 3.6.0

EULA OSS GitHub

Git Info from MSBuild, C# and VB

[!NOTE] 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.

Open Source Maintenance Fee

To ensure the long-term sustainability of this project, users of this package who generate revenue must pay an Open Source Maintenance Fee. While the source code is freely available under the terms of the License, this package and other aspects of the project require adherence to the Maintenance Fee.

To pay the Maintenance Fee, become a Sponsor at the proper OSMF tier. A single fee covers all of Devlooped packages.

Usage

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.

You can also just build your own versioning logic in a target that depends on GitInfo using plain MSBuild:

<PropertyGroup>
  <GitVersion>false</GitVersion> <!-- we'll do our own versioning -->
</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

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 MFB Technologies, Inc. DRIVE.NET, Inc. Keith Pickford Thomas Bolon Kori Francis Uno Platform Reuben Swartz Jacob Foshee Eric Johnson David JENNI Jonathan Charley Wu Ken Bonny Simon Cropp agileworks-eu Zheyu Shen Vezel ChilliCream 4OTC Vincent Limo Jordan S. Jones domischell Justin Wendlandt Adrian Alonso Michael Hagedorn torutek mccaffers

Sponsor this project  

Learn more about GitHub Sponsors

No packages depend on GitInfo.

https://github.com/devlooped/GitInfo/blob/main/changelog.md

.NET Standard 2.0

Version Downloads Last updated
3.6.0 4 10/19/2025
3.5.0 25 12/13/2024
3.3.5 21 12/19/2024
3.3.4 26 12/11/2024
3.3.3 21 12/02/2024
3.3.2 21 12/14/2024
3.3.1 21 12/15/2024
3.3.0 21 12/08/2024
3.2.0 18 12/11/2024
2.3.0 19 12/15/2024
2.2.1 22 12/15/2024
2.2.0 23 12/15/2024
2.1.2 21 12/29/2024
2.1.1 24 12/11/2024
2.0.40 19 12/06/2024
2.0.39 20 12/01/2024
2.0.38 23 12/12/2024
2.0.37 22 12/29/2024
2.0.36 24 11/22/2024
2.0.35 18 12/11/2024
2.0.34 26 01/13/2023
2.0.33 20 12/11/2024
2.0.32 21 12/19/2024
2.0.31 20 12/15/2024
2.0.30 22 12/11/2024
2.0.29 20 12/11/2024
2.0.28 21 12/12/2024
2.0.27 19 12/11/2024
2.0.26 21 12/11/2024
2.0.25 19 12/11/2024
2.0.21 20 12/12/2024
2.0.20 19 12/08/2024
2.0.19 19 12/12/2024
2.0.18 20 12/12/2024
2.0.17 19 12/11/2024
2.0.16 20 12/19/2024
2.0.15 24 12/16/2024
2.0.14 19 12/11/2024
2.0.11 22 12/12/2024
2.0.10 22 12/15/2024
2.0.9 19 12/14/2024
2.0.8 22 12/15/2024
2.0.7 22 12/21/2024
2.0.6 18 12/09/2024
2.0.5 21 12/11/2024
2.0.3 19 12/16/2024
2.0.2 19 12/12/2024
2.0.1 20 12/16/2024
2.0.0 23 12/11/2024
1.1.72 23 12/15/2024
1.1.71 22 12/07/2024
1.1.70 21 12/15/2024
1.1.68 21 11/29/2024
1.1.67 20 12/12/2024
1.1.66 20 12/15/2024
1.1.65 23 12/19/2024
1.1.63 21 12/11/2024
1.1.62 23 12/11/2024
1.1.61 23 12/22/2024
1.1.60 22 12/11/2024
1.1.59 20 12/11/2024
1.1.58 21 12/11/2024
1.1.57 21 12/14/2024
1.1.56 20 12/15/2024
1.1.55 20 12/15/2024
1.1.54 22 12/04/2024
1.1.53 22 12/11/2024
1.1.48 22 12/11/2024
1.1.47 23 11/25/2024
1.1.45 20 12/29/2024
1.1.44 20 12/11/2024
1.1.43 19 12/15/2024
1.1.41 18 12/22/2024
1.1.40 19 12/11/2024
1.1.39 22 12/12/2024
1.1.38 19 12/15/2024
1.1.37 20 12/11/2024
1.1.35 23 12/11/2024
1.1.34 17 12/16/2024
1.1.31 20 12/15/2024
1.1.30 20 12/08/2024
1.1.29 21 12/15/2024
1.1.28 20 12/19/2024
1.1.27 22 12/16/2024
1.1.26 22 12/19/2024
1.1.25 20 12/15/2024
1.1.24 21 12/15/2024
1.1.23 21 12/12/2024
1.1.22 20 12/12/2024
1.1.20 22 12/16/2024
1.1.19 21 12/11/2024
1.1.17 20 12/12/2024
1.1.15 20 12/16/2024
1.1.14 20 12/15/2024
1.1.13 23 11/24/2024
1.1.12 17 12/11/2024
1.1.10 21 12/11/2024
1.1.9 20 12/11/2024
1.1.8 18 12/11/2024
1.1.7 21 12/16/2024
1.1.5 18 12/15/2024
1.1.4 19 12/15/2024
1.1.2 21 11/12/2024
1.1.1 23 12/03/2024
1.1.0 19 12/11/2024
1.0.64-pre 22 12/11/2024
1.0.63-pre 21 12/11/2024
1.0.62-pre 23 12/15/2024
1.0.61-pre 20 12/19/2024
1.0.60-pre 22 12/09/2024
1.0.59-pre 23 12/19/2024
1.0.58-pre 20 12/11/2024
1.0.56-pre 22 12/11/2024
1.0.55-pre 21 12/19/2024
1.0.54-pre 19 12/23/2024
1.0.53-pre 22 12/11/2024
1.0.52-pre 19 12/11/2024
1.0.51-pre 19 12/09/2024
1.0.50-pre 20 12/11/2024
1.0.49-pre 29 12/19/2024
1.0.48-pre 20 12/20/2024
1.0.47-pre 21 12/19/2024
1.0.46-pre 19 12/15/2024
1.0.45-pre 22 12/11/2024
1.0.44-pre 22 12/29/2024
1.0.43-pre 20 12/11/2024
1.0.42-pre 27 12/19/2024
1.0.41-pre 19 12/11/2024
1.0.40-pre 23 12/20/2024
1.0.39-pre 19 12/16/2024
1.0.38-pre 22 12/11/2024
1.0.37-pre 22 12/12/2024
1.0.36-pre 26 12/15/2024
1.0.35-pre 20 12/16/2024
1.0.34-pre 21 12/19/2024
1.0.33-pre 24 11/22/2024
1.0.31-pre 27 12/22/2024
1.0.30-pre 23 12/12/2024
1.0.29-pre 22 12/03/2024
1.0.28-pre 20 12/11/2024
1.0.27-pre 22 12/16/2024
1.0.26-pre 19 12/11/2024
1.0.25-pre 22 12/29/2024
1.0.24-pre 20 12/29/2024
1.0.23-pre 17 12/29/2024
1.0.22-pre 21 12/11/2024
1.0.21-pre 19 12/19/2024
1.0.20-pre 19 12/19/2024
1.0.19-pre 20 12/20/2024
1.0.18-pre 24 12/06/2024
1.0.16-pre 18 12/15/2024
1.0.15-pre 20 12/07/2024
1.0.14-pre 21 12/12/2024
1.0.11-pre 20 12/11/2024
1.0.10-pre 19 12/06/2024
1.0.9-pre 21 12/15/2024
1.0.8-pre 23 12/11/2024
1.0.7-pre 19 12/12/2024
1.0.6-pre 20 12/12/2024
1.0.5-pre 21 12/18/2024
1.0.4-pre 19 12/11/2024
1.0.3-pre 20 12/11/2024
1.0.1-pre 25 12/11/2024
1.0.0 20 12/19/2024
1.0.0-pre 18 12/11/2024
0.0.196 22 12/20/2024
0.0.195 22 12/29/2024
0.0.194 22 12/11/2024