RSCG – Larcanum.GitInfo
 
 
| name | Larcanum.GitInfo | 
| nuget | https://www.nuget.org/packages/Larcanum.GitInfo/ | 
| link | https://github.com/lord-executor/Larcanum.GitInfo | 
| author | 
Generates GitInfo data from the current environment.
This is how you can use Larcanum.GitInfo .
The code that you start with is
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
	
	<PropertyGroup>
		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
	</PropertyGroup>
	
	<ItemGroup>
	  <PackageReference Include="Larcanum.GitInfo" Version="1.1.0">
	    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
	    <PrivateAssets>all</PrivateAssets>
	  </PackageReference>
	</ItemGroup>
</Project>
The code that you will use is
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello,World!");
Console.WriteLine($"Version: {DemoGit.GitInfo.Branch}");
Console.WriteLine($"Version: {DemoGit.GitInfo.CommitDate}");
The code that is generated is
// <auto-generated />
// Generator Context
// ProjectDir: D:\gth\RSCG_Examples\v2\rscg_examples\Larcanum.GitInfo\src\DemoGit\DemoGit\
// GitInfoNamespace: DemoGit
// GitInfoGlobalNamespace: False
// GitInfoGitBin: git
// GitInfoVersionRegex: v?(?<VERSION>(?<MAJOR>\d+)\.(?<MINOR>\d+)(?:\.(?<PATCH>\d+))?(?:[-+](?<LABEL>[\dA-Za-z\-\.]+))?)$
// GitInfoGenerateAssemblyVersion: True
// GitInfoDebug: False
// GitPath: C:\Program Files\Git\cmd\git.exe
// GitVersion: git version 2.42.0.windows.2
// GitRoot: D:/gth/RSCG_Examples
// GitFingerprint: vPureDI3-7-g5308331d7
// Timestamp: 2025-01-18T15:18:22.4819389+02:00
[assembly: System.Reflection.AssemblyVersion("1.0.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersion("vPureDI3-7-g5308331d7")]
namespace DemoGit;
/// <summary>Provides access to the git information for the current assembly.</summary>
internal partial class GitInfo
{
    public const bool IsDirty = false;
    public const string Branch = @"Larcanum.GitInfo";
    public const string CommitShortHash = @"5308331d7";
    public const string CommitHash = @"5308331d78c3674c7354749ac82d7b1199277997";
    public const string CommitDate = @"2024-12-24T19:19:30+02:00";
    public const string Tag = @"vPureDI3-7-g5308331d7";
    public const string DotNetVersion = @"1.0.0.0";
}
Code and pdf at
https://ignatandrei.github.io/RSCG_Examples/v2/docs/Larcanum.GitInfo
Leave a Reply