SimplestGitSourceGenerator 1.0.4

dotnet add package SimplestGitSourceGenerator --version 1.0.4
                    
NuGet\Install-Package SimplestGitSourceGenerator -Version 1.0.4
                    
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="SimplestGitSourceGenerator" Version="1.0.4">
  <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.
<PackageVersion Include="SimplestGitSourceGenerator" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="SimplestGitSourceGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SimplestGitSourceGenerator --version 1.0.4
                    
#r "nuget: SimplestGitSourceGenerator, 1.0.4"
                    
#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.
#:package SimplestGitSourceGenerator@1.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SimplestGitSourceGenerator&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=SimplestGitSourceGenerator&version=1.0.4
                    
Install as a Cake Tool

SimplestGitSourceGenerator

Nuget GitHub release (latest by date including pre-releases)

Happy to showcase the simplest solution for retrieving Git information in your .NET apps.

Requirements

  • Project must be a Git repository with at least 1 commit
  • Git must be installed

If these requirements are not fulfilled, the build will not pass!

Usage

Install the NuGet package:

dotnet add package SimplestGitSourceGenerator

Code:

using SimplestGitSourceGenerator;

Console.WriteLine(SimplestGit.CommitHash);
Console.WriteLine(SimplestGit.CommitDate);
Console.WriteLine(SimplestGit.Branch);
Console.WriteLine(SimplestGit.Tag);

If you want to include remote URL as well, you can enable it via property:

<PropertyGroup>
    <PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>

Once that's done, you can access it via SimplestGit.RemoteUrl.

Docker build

Ensure that you remove .git folders from your .dockerignore file and that you multi-stage your build so that the .git folder is not included in the final image.

Make sure to install git before building your project (Alpine example):

RUN apk add --no-cache git

How does it work?

Before the source generator kicks in, several Git commands are called and stored as compiler properties before they are baked into the code.

  • git rev-parse HEAD (SimplestGitCommitHash)
  • git rev-parse --abbrev-ref HEAD (SimplestGitBranch)
  • git log -1 --format=%cI (SimplestGitCommitDate)
  • git describe --tags --always (SimplestGitTag)
  • git ls-remote --get-url (SimplestGitRemoteUrl)

These commands must complete with the exit code 0, otherwise, the build will not pass. All of that is done thanks to the build/SimplestGitSourceGenerator.targets file.

This is a simpler alternative to SourceLink or GitInfo packages if you don't mind requiring the Git dependency.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 103 5/24/2026
1.0.3 348 1/13/2026
1.0.2 121 1/13/2026
1.0.1 118 1/13/2026