SimplestGitSourceGenerator 1.0.1
See the version list below for details.
dotnet add package SimplestGitSourceGenerator --version 1.0.1
NuGet\Install-Package SimplestGitSourceGenerator -Version 1.0.1
<PackageReference Include="SimplestGitSourceGenerator" Version="1.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="SimplestGitSourceGenerator" Version="1.0.1" />
<PackageReference Include="SimplestGitSourceGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add SimplestGitSourceGenerator --version 1.0.1
#r "nuget: SimplestGitSourceGenerator, 1.0.1"
#:package SimplestGitSourceGenerator@1.0.1
#addin nuget:?package=SimplestGitSourceGenerator&version=1.0.1
#tool nuget:?package=SimplestGitSourceGenerator&version=1.0.1
SimplestGitSourceGenerator
Happy to showcase the simplest solution for retrieving Git information in your .NET apps.
Requirements
- Project must be a Git repository
- 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);
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.
SimplestGitCommitHash-git rev-parse HEADSimplestGitBranch-git rev-parse --abbrev-ref HEADSimplestGitCommitDate-git log -1 --format=%cISimplestGitTag-git describe --tags --always
These commands must complete with the exit code 0, otherwise, the build will not pass. All of that is done thanks to the build/SimplestGit.targets file.
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.